X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=e53824770527f5cf37d40440f9ac397741d27914;hb=fc0e0bbda277a99354170a4b8de6eb1275920555;hp=0375d0cd1adb41a718da997d83fb4f238c50efd8;hpb=7840048031b19bd4af654285aa855826be6fa544;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 0375d0c..e538247 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -23,21 +23,39 @@ do { } }, before => sub { - return sub { } + my $caller = $CALLER; + return sub { + my $code = pop; + for (@_) { + $caller->meta->add_before_method_modifier($_ => $code); + } + } }, after => sub { - return sub { } + my $caller = $CALLER; + return sub { + my $code = pop; + for (@_) { + $caller->meta->add_before_method_modifier($_ => $code); + } + } }, around => sub { - return sub { } + my $caller = $CALLER; + return sub { + my $code = pop; + for (@_) { + $caller->meta->add_before_method_modifier($_ => $code); + } + } }, has => sub { my $caller = $CALLER; return sub { my $name = shift; - my @opts = @_; + my %opts = @_; - $caller->meta->add_attribute($name => \@opts); + $caller->meta->add_attribute($name => \%opts); } }, with => sub { @@ -86,3 +104,56 @@ do { 1; +__END__ + +=head1 NAME + +Mouse::Role + +=head1 KEYWORDS + +=head2 meta -> Mouse::Meta::Role + +Returns this role's metaclass instance. + +=head2 before (method|methods) => Code + +Sets up a "before" method modifier. See L or +L. + +=head2 after (method|methods) => Code + +Sets up an "after" method modifier. See L or +L. + +=head2 around (method|methods) => Code + +Sets up an "around" method modifier. See L or +L. + +=head2 has (name|names) => parameters + +Sets up an attribute (or if passed an arrayref of names, multiple attributes) to +this role. See L. + +=head2 confess error -> BOOM + +L for your convenience. + +=head2 blessed value -> ClassName | undef + +L for your convenience. + +=head1 MISC + +=head2 import + +Importing Mouse::Role will give you sugar. + +=head2 unimport + +Please unimport Mouse (C) so that if someone calls one of the +keywords (such as L) it will break loudly instead breaking subtly. + +=cut +