X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoo.pm;h=f4023cba31ee26110257b58578e0843eb0b83992;hb=64284a1b21ce94c351f555f0e74929e4ff8ad323;hp=14625316a11cbbaf2c02c30300986e34900163c1;hpb=239d4711db5f4bdc5e621083d24b64b72e68a784;p=gitmo%2FMoo.git diff --git a/lib/Moo.pm b/lib/Moo.pm index 1462531..f4023cb 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -3,8 +3,9 @@ package Moo; use strictures 1; use Moo::_Utils; use B 'perlstring'; +use Sub::Defer (); -our $VERSION = '0.009_017'; # 0.9.17 +our $VERSION = '0.091001'; # 0.91.1 $VERSION = eval $VERSION; require Moo::sification; @@ -33,12 +34,10 @@ sub import { $MAKERS{$target} = {}; _install_coderef "${target}::has" => sub { my ($name, %spec) = @_; - ($MAKERS{$target}{accessor} ||= do { - require Method::Generate::Accessor; - Method::Generate::Accessor->new - })->generate_method($target, $name, \%spec); $class->_constructor_maker_for($target) ->register_attribute_specs($name, \%spec); + $class->_accessor_maker_for($target) + ->generate_method($target, $name, \%spec); }; foreach my $type (qw(before after around)) { _install_coderef "${target}::${type}" => sub { @@ -57,6 +56,31 @@ sub import { } } +sub _accessor_maker_for { + my ($class, $target) = @_; + return unless $MAKERS{$target}; + $MAKERS{$target}{accessor} ||= do { + my $maker_class = do { + if (my $m = do { + if (my $defer_target = + (Sub::Defer::defer_info($target->can('new'))||[])->[0] + ) { + my ($pkg) = ($defer_target =~ /^(.*)::[^:]+$/); + $MAKERS{$pkg} && $MAKERS{$pkg}{accessor}; + } else { + undef; + } + }) { + ref($m); + } else { + require Method::Generate::Accessor; + 'Method::Generate::Accessor' + } + }; + $maker_class->new; + } +} + sub _constructor_maker_for { my ($class, $target, $select_super) = @_; return unless $MAKERS{$target}; @@ -84,13 +108,10 @@ sub _constructor_maker_for { $moo_constructor = 1; # no other constructor, make a Moo one } }; - Method::Generate::Constructor + ($con ? ref($con) : 'Method::Generate::Constructor') ->new( package => $target, - accessor_generator => do { - require Method::Generate::Accessor; - Method::Generate::Accessor->new; - }, + accessor_generator => $class->_accessor_maker_for($target), construction_string => ( $moo_constructor ? ($con ? $con->construction_string : undef) @@ -200,8 +221,11 @@ L everywhere. Extending a L class or consuming a L should also work. -However, these features are new as of 0.91.0 (0.091000) so they may not -be 100% yet; please do report bugs. +This means that there is no need for anything like L for Moo +code - Moo and Moose code should simply interoperate without problem. + +However, these features are new as of 0.91.0 (0.091000) so while serviceable, +they are absolutely certain to not be 100% yet; please do report bugs. If you need to disable the metaclass creation, add: @@ -550,6 +574,10 @@ at the end of your class to get an inlined (i.e. not horribly slow) constructor. Moo does it automatically the first time ->new is called on your class. +=head1 SUPPORT + +IRC: #web-simple on irc.perl.org + =head1 AUTHOR mst - Matt S. Trout (cpan:MSTROUT)