X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=4a9a08b071b032e1b04ea505d99372e2bc23bb49;hb=cadd5b5ee44fc5a2c6456a188a1b2a48fc436a05;hp=3392f3e3e68cc5e96ca545491c7c22f297d8fd83;hpb=26482d3ff20c9e131b14e5fbf949b0eeadcea7c6;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 3392f3e..4a9a08b 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -5,11 +5,18 @@ use warnings; use Sub::Exporter; use Carp 'confess'; +use Scalar::Util; + +use Mouse::Meta::Role; do { my $CALLER; my %exports = ( + meta => sub { + my $meta = Mouse::Meta::Role->initialize($CALLER); + return sub { $meta }; + }, extends => sub { return sub { confess "Role does not currently support 'extends'"; @@ -25,8 +32,31 @@ do { return sub { } }, has => sub { + my $caller = $CALLER; + return sub { + my $name = shift; + my %opts = @_; + + $caller->meta->add_attribute($name => \%opts); + } + }, + with => sub { + return sub { + confess "Role does not currently support 'with'"; + } + }, + requires => sub { return sub { } }, + excludes => sub { + return sub { } + }, + blessed => sub { + return \&Scalar::Util::blessed; + }, + confess => sub { + return \&Carp::confess; + }, ); my $exporter = Sub::Exporter::build_exporter({ @@ -44,8 +74,68 @@ do { } sub unimport { + my $caller = caller; + + no strict 'refs'; + for my $keyword (keys %exports) { + next if $keyword eq 'meta'; # we don't delete this one + delete ${ $caller . '::' }{$keyword}; + } } }; 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 +