From: Dave Rolsky Date: Sat, 2 Aug 2008 03:48:01 +0000 (+0000) Subject: Having init_meta() in the same scope as $CALLER always makes me look X-Git-Tag: 0_55~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc841c0ef1135c3c40391b8efe87c23adba7d1b9;p=gitmo%2FMoose.git Having init_meta() in the same scope as $CALLER always makes me look for how init_meta() uses $CALLER, but it _doesn't_, so I'm moving it. --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 9b0fb44..293a452 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -29,52 +29,6 @@ use Moose::Util (); { my $CALLER; - sub init_meta { - my ( $class, $base_class, $metaclass ) = @_; - $base_class = 'Moose::Object' unless defined $base_class; - $metaclass = 'Moose::Meta::Class' unless defined $metaclass; - - confess - "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." - unless $metaclass->isa('Moose::Meta::Class'); - - # make a subtype for each Moose class - class_type($class) - unless find_type_constraint($class); - - my $meta; - if ( $class->can('meta') ) { - # NOTE: - # this is the case where the metaclass pragma - # was used before the 'use Moose' statement to - # override a specific class - $meta = $class->meta(); - ( blessed($meta) && $meta->isa('Moose::Meta::Class') ) - || confess "You already have a &meta function, but it does not return a Moose::Meta::Class"; - } - else { - # NOTE: - # this is broken currently, we actually need - # to allow the possiblity of an inherited - # meta, which will not be visible until the - # user 'extends' first. This needs to have - # more intelligence to it - $meta = $metaclass->initialize($class); - $meta->add_method( - 'meta' => sub { - # re-initialize so it inherits properly - $metaclass->initialize( blessed( $_[0] ) || $_[0] ); - } - ); - } - - # make sure they inherit from Moose::Object - $meta->superclasses($base_class) - unless $meta->superclasses(); - - return $meta; - } - my %exports = ( extends => sub { my $class = $CALLER; @@ -258,6 +212,52 @@ use Moose::Util (); } +sub init_meta { + my ( $class, $base_class, $metaclass ) = @_; + $base_class = 'Moose::Object' unless defined $base_class; + $metaclass = 'Moose::Meta::Class' unless defined $metaclass; + + confess + "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." + unless $metaclass->isa('Moose::Meta::Class'); + + # make a subtype for each Moose class + class_type($class) + unless find_type_constraint($class); + + my $meta; + if ( $class->can('meta') ) { + # NOTE: + # this is the case where the metaclass pragma + # was used before the 'use Moose' statement to + # override a specific class + $meta = $class->meta(); + ( blessed($meta) && $meta->isa('Moose::Meta::Class') ) + || confess "You already have a &meta function, but it does not return a Moose::Meta::Class"; + } + else { + # NOTE: + # this is broken currently, we actually need + # to allow the possiblity of an inherited + # meta, which will not be visible until the + # user 'extends' first. This needs to have + # more intelligence to it + $meta = $metaclass->initialize($class); + $meta->add_method( + 'meta' => sub { + # re-initialize so it inherits properly + $metaclass->initialize( blessed( $_[0] ) || $_[0] ); + } + ); + } + + # make sure they inherit from Moose::Object + $meta->superclasses($base_class) + unless $meta->superclasses(); + + return $meta; +} + ## make 'em all immutable $_->meta->make_immutable(