From: Stevan Little Date: Wed, 19 Apr 2006 00:41:39 +0000 (+0000) Subject: moooooose X-Git-Tag: 0_05~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d5624210ae9395ee82c00996b7516dfe246edbe;p=gitmo%2FMoose.git moooooose --- diff --git a/Build.PL b/Build.PL index cf0a0cb..5679b16 100644 --- a/Build.PL +++ b/Build.PL @@ -10,7 +10,8 @@ my $build = Module::Build->new( 'Carp' => '0', 'Class::MOP' => '0.22', 'Sub::Name' => '0.02', - 'UNIVERSAL::require' => '0' + 'UNIVERSAL::require' => '0', + 'Sub::Exporter' => '0', # update this when rjbs releases }, optional => { }, diff --git a/Changes b/Changes index bb4ce62..8da8df4 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,13 @@ Revision history for Perl extension Moose 0.05 + * Moose + - keywords are now exported with Sub::Exporter + thanks to chansen for this commit + + * Moose::Role + - keywords are now exported with Sub::Exporter + * Moose::Utils::TypeConstraints - added Bool type and CollectionRef type then made ArrayRef and HashRef into subtypes diff --git a/README b/README index e4af674..fd009ac 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Moose version 0.04 +Moose version 0.05 =========================== See the individual module documentation for more information diff --git a/lib/Moose.pm b/lib/Moose.pm index b691135..a3cc118 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,13 +4,14 @@ package Moose; use strict; use warnings; -our $VERSION = '0.04'; +our $VERSION = '0.05'; use Scalar::Util 'blessed', 'reftype'; use Carp 'confess'; use Sub::Name 'subname'; use UNIVERSAL::require; +use Sub::Exporter; use Class::MOP; @@ -21,12 +22,11 @@ use Moose::Meta::Attribute; use Moose::Object; use Moose::Util::TypeConstraints; -use Sub::Exporter; { my ( $CALLER, %METAS ); - sub meta() { + sub _find_meta { my $class = $CALLER; return $METAS{$class} if exists $METAS{$class}; @@ -64,14 +64,14 @@ use Sub::Exporter; my %exports = ( extends => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::extends' => sub { _load_all_classes(@_); $meta->superclasses(@_) }; }, with => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::with' => sub { my ($role) = @_; _load_all_classes($role); @@ -79,50 +79,50 @@ use Sub::Exporter; }; }, has => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::has' => sub { my ($name, %options) = @_; $meta->add_attribute($name, %options) }; }, before => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::before' => sub { my $code = pop @_; $meta->add_before_method_modifier($_, $code) for @_; }; }, after => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::after' => sub { my $code = pop @_; $meta->add_after_method_modifier($_, $code) for @_; }; }, around => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::around' => sub { my $code = pop @_; $meta->add_around_method_modifier($_, $code) for @_; }; }, super => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::super' => sub {}; }, override => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::override' => sub { my ($name, $method) = @_; $meta->add_override_method_modifier($name => $method); }; }, inner => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::inner' => sub {}; }, augment => sub { - my $meta = meta(); + my $meta = _find_meta(); return subname 'Moose::augment' => sub { my ($name, $method) = @_; $meta->add_augment_method_modifier($name => $method); diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 6821d8f..5299a79 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -8,86 +8,131 @@ use Scalar::Util (); use Carp 'confess'; use Sub::Name 'subname'; -our $VERSION = '0.02'; +use Sub::Exporter; + +our $VERSION = '0.03'; use Moose::Meta::Role; -sub import { - shift; - my $pkg = caller(); - - # we should never export to main - return if $pkg eq 'main'; - - my $meta; - if ($pkg->can('meta')) { - $meta = $pkg->meta(); - (blessed($meta) && $meta->isa('Moose::Meta::Role')) - || confess "Whoops, not møøsey enough"; - } - else { - $meta = Moose::Meta::Role->new(role_name => $pkg); - $meta->_role_meta->add_method('meta' => sub { $meta }) - } - - # NOTE: - # &alias_method will install the method, but it - # will not name it with - - # handle superclasses - $meta->alias_method('extends' => subname 'Moose::Role::extends' => sub { - confess "Moose::Role does not currently support 'extends'" - }); - - # handle roles - $meta->alias_method('with' => subname 'Moose::with' => sub { - my ($role) = @_; - Moose::_load_all_classes($role); - $role->meta->apply($meta); - }); - - # required methods - $meta->alias_method('requires' => subname 'Moose::requires' => sub { - $meta->add_required_methods(@_); - }); - - # handle attributes - $meta->alias_method('has' => subname 'Moose::Role::has' => sub { - my ($name, %options) = @_; - $meta->add_attribute($name, %options) - }); - - # handle method modifers - $meta->alias_method('before' => subname 'Moose::Role::before' => sub { - my $code = pop @_; - $meta->add_before_method_modifier($_, $code) for @_; - }); - $meta->alias_method('after' => subname 'Moose::Role::after' => sub { - my $code = pop @_; - $meta->add_after_method_modifier($_, $code) for @_; - }); - $meta->alias_method('around' => subname 'Moose::Role::around' => sub { - my $code = pop @_; - $meta->add_around_method_modifier($_, $code) for @_; - }); - - $meta->alias_method('super' => subname 'Moose::Role::super' => sub {}); - $meta->alias_method('override' => subname 'Moose::Role::override' => sub { - my ($name, $code) = @_; - $meta->add_override_method_modifier($name, $code); - }); +{ + my ( $CALLER, %METAS ); + + sub _find_meta { + my $class = $CALLER; + + return $METAS{$class} if exists $METAS{$class}; + + my $meta; + if ($class->can('meta')) { + $meta = $class->meta(); + (blessed($meta) && $meta->isa('Moose::Meta::Role')) + || confess "Whoops, not møøsey enough"; + } + else { + $meta = Moose::Meta::Role->new(role_name => $class); + $meta->_role_meta->add_method('meta' => sub { $meta }) + } + + return $METAS{$class} = $meta; + } + - $meta->alias_method('inner' => subname 'Moose::Role::inner' => sub { - confess "Moose::Role does not currently support 'inner'"; - }); - $meta->alias_method('augment' => subname 'Moose::Role::augment' => sub { - confess "Moose::Role does not currently support 'augment'"; - }); - - # we recommend using these things - # so export them for them - $meta->alias_method('confess' => \&Carp::confess); - $meta->alias_method('blessed' => \&Scalar::Util::blessed); + my %exports = ( + extends => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::extends' => sub { + confess "Moose::Role does not currently support 'extends'" + }; + }, + with => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::with' => sub { + my ($role) = @_; + Moose::_load_all_classes($role); + $role->meta->apply($meta); + }; + }, + requires => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::requires' => sub { + $meta->add_required_methods(@_); + }; + }, + has => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::has' => sub { + my ($name, %options) = @_; + $meta->add_attribute($name, %options) + }; + }, + before => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::before' => sub { + my $code = pop @_; + $meta->add_before_method_modifier($_, $code) for @_; + }; + }, + after => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::after' => sub { + my $code = pop @_; + $meta->add_after_method_modifier($_, $code) for @_; + }; + }, + around => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::around' => sub { + my $code = pop @_; + $meta->add_around_method_modifier($_, $code) for @_; + }; + }, + super => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::super' => sub {}; + }, + override => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::override' => sub { + my ($name, $code) = @_; + $meta->add_override_method_modifier($name, $code); + }; + }, + inner => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::inner' => sub { + confess "Moose::Role does not currently support 'inner'"; + }; + }, + augment => sub { + my $meta = _find_meta(); + return subname 'Moose::Role::augment' => sub { + confess "Moose::Role does not currently support 'augment'"; + }; + }, + confess => sub { + return \&Carp::confess; + }, + blessed => sub { + return \&Scalar::Util::blessed; + } + ); + + my $exporter = Sub::Exporter::build_exporter({ + exports => \%exports, + groups => { + default => [':all'] + } + }); + + sub import { + $CALLER = caller(); + + # we should never export to main + return if $CALLER eq 'main'; + + goto $exporter; + }; + } 1;