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;
$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 {
}
}
+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};
$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)
Extending a L<Moose> class or consuming a L<Moose::Role> 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<Any::Moose> 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:
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) <mst@shadowcat.co.uk>