X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FRole%2FParameterized.pm;h=0b5c9619d2a89d3be1772d1b5f3204ab889c69a9;hb=bfac2339a5b1a32f8b718660e9baf22edc1b59d6;hp=00d4af9f14505b6649270bb786759cb585cb38fe;hpb=ff2ccd89f306215ee3a6625e1da43b5624e758ea;p=gitmo%2FMooseX-Role-Parameterized.git diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index 00d4af9..0b5c961 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -1,14 +1,12 @@ package MooseX::Role::Parameterized; - use Moose ( extends => { -as => 'moose_extends' }, around => { -as => 'moose_around' }, qw/confess blessed/, ); +moose_extends 'Moose::Exporter'; -use Carp 'croak'; use Moose::Role (); -moose_extends 'Moose::Exporter'; use MooseX::Role::Parameterized::Meta::Role::Parameterizable; @@ -23,6 +21,10 @@ __PACKAGE__->setup_import_methods( sub parameter { my $caller = shift; + + confess "'parameter' may not be used inside of the role block" + if $CURRENT_METACLASS; + my $meta = Class::MOP::Class->initialize($caller); my $names = shift; @@ -33,7 +35,7 @@ sub parameter { } } -sub role { +sub role (&) { my $caller = shift; my $role_generator = shift; Class::MOP::Class->initialize($caller)->role_generator($role_generator); @@ -47,18 +49,6 @@ sub init_meta { ); } -# give role a (&) prototype -moose_around _make_wrapper => sub { - my $orig = shift; - my ($self, $caller, $sub, $fq_name) = @_; - - if ($fq_name =~ /::role$/) { - return sub (&) { $sub->($caller, @_) }; - } - - return $orig->(@_); -}; - sub has { my $caller = shift; my $meta = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller); @@ -94,7 +84,7 @@ sub before { my $code = pop @_; for (@_) { - croak "Roles do not currently support " + Carp::croak "Roles do not currently support " . ref($_) . " references for before method modifiers" if ref $_; @@ -109,7 +99,7 @@ sub after { my $code = pop @_; for (@_) { - croak "Roles do not currently support " + Carp::croak "Roles do not currently support " . ref($_) . " references for after method modifiers" if ref $_; @@ -124,7 +114,7 @@ sub around { my $code = pop @_; for (@_) { - croak "Roles do not currently support " + Carp::croak "Roles do not currently support " . ref($_) . " references for around method modifiers" if ref $_; @@ -143,7 +133,7 @@ sub requires { my $caller = shift; my $meta = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller); - croak "Must specify at least one method" unless @_; + Carp::croak "Must specify at least one method" unless @_; $meta->add_required_methods(@_); } @@ -151,7 +141,7 @@ sub excludes { my $caller = shift; my $meta = $CURRENT_METACLASS || Class::MOP::Class->initialize($caller); - croak "Must specify at least one role" unless @_; + Carp::croak "Must specify at least one role" unless @_; $meta->add_excluded_roles(@_); } @@ -169,11 +159,11 @@ sub override { $meta->add_override_method_modifier($name, $code); } -sub extends { croak "Roles do not currently support 'extends'" } +sub extends { Carp::croak "Roles do not currently support 'extends'" } -sub inner { croak "Roles cannot support 'inner'" } +sub inner { Carp::croak "Roles cannot support 'inner'" } -sub augment { croak "Roles cannot support 'augment'" } +sub augment { Carp::croak "Roles cannot support 'augment'" } 1; @@ -189,7 +179,6 @@ MooseX::Role::Parameterized - parameterized roles use MooseX::Role::Parameterized; parameter name => ( - is => 'ro', isa => 'Str', required => 1, ); @@ -232,8 +221,9 @@ Your parameterized role consists of two things: parameter declarations and a C block. Parameters are declared using the L keyword which very much -resembles L. You can use any option that L accepts. -These parameters will get their values when the consuming class (or role) uses +resembles L. You can use any option that L accepts. The +default value for the "is" option is "ro" as that's a very common case. These +parameters will get their values when the consuming class (or role) uses L. A parameter object will be constructed with these values, and passed to the C block. @@ -253,12 +243,6 @@ You must use this syntax to declare methods in the role block: C<< method NAME => sub { ... }; >>. This is due to a limitation in Perl. In return though you can use parameters I! -You must use all the keywords in the role block. If it turns out to be correct, -we'll compose the parameterizable role (everything outside the role block) with -the parameterized role (everything inside the role block). We throw an error if -you try to use a keyword outside of the role block, so don't worry about it for -now. - L and L are not yet supported. I'm completely unsure of whether they should be handled by this module. Until we figure out a plan, both declaring and providing a parameter named C or @@ -268,5 +252,29 @@ C is an error. Shawn M Moore, C<< >> +=head1 EXAMPLES + +=over 4 + +=item L + +=item L + +=item L + +=item L + +=item L + +=item L + +=item L + +=item L + +=item L + +=back + =cut