our %MAKERS;
+sub _install_tracked {
+ my ($target, $name, $code) = @_;
+ $MAKERS{$target}{exports}{$name} = $code;
+ _install_coderef "${target}::${name}" => "Moo::${name}" => $code;
+}
+
sub import {
my $target = caller;
my $class = shift;
strictures->import;
return if $MAKERS{$target}; # already exported into this package
- _install_coderef "${target}::extends" => "Moo::extends" => sub {
+ $MAKERS{$target} = {};
+ _install_tracked $target => extends => sub {
_load_module($_) for @_;
# Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA
@{*{_getglob("${target}::ISA")}{ARRAY}} = @_;
Moo->_constructor_maker_for($target)
->register_attribute_specs(%{$old->all_attribute_specs});
}
+ no warnings 'once'; # piss off. -- mst
$Moo::HandleMoose::MOUSE{$target} = [
grep defined, map Mouse::Util::find_meta($_), @_
] if $INC{"Mouse.pm"};
$class->_maybe_reset_handlemoose($target);
return;
};
- _install_coderef "${target}::with" => "Moo::with" => sub {
+ _install_tracked $target => with => sub {
require Moo::Role;
Moo::Role->apply_roles_to_package($target, @_);
$class->_maybe_reset_handlemoose($target);
};
- $MAKERS{$target} = {};
- _install_coderef "${target}::has" => "Moo::has" => sub {
+ _install_tracked $target => has => sub {
my ($name, %spec) = @_;
$class->_constructor_maker_for($target)
->register_attribute_specs($name, \%spec);
return;
};
foreach my $type (qw(before after around)) {
- _install_coderef "${target}::${type}" => "Moo::${type}" => sub {
+ _install_tracked $target => $type => sub {
require Class::Method::Modifiers;
_install_modifier($target, $type, @_);
return;
}
}
+sub unimport {
+ my $target = caller;
+ _unimport_coderefs($target, $MAKERS{$target});
+}
+
sub _maybe_reset_handlemoose {
my ($class, $target) = @_;
if ($INC{"Moo/HandleMoose.pm"}) {
' if ($Moo::MAKERS{$class}) {'."\n"
.' '.$class.'->_constructor_maker_for($class,'.perlstring($target).');'."\n"
.' return $class->new(@_)'.";\n"
+ .' } elsif ($INC{"Moose.pm"} and my $meta = Class::MOP::get_metaclass_by_name($class)) {'."\n"
+ .' return $meta->new_object(@_);'."\n"
.' }'."\n"
),
)
=head1 SUPPORT
-IRC: #web-simple on irc.perl.org
+IRC: #moose on irc.perl.org
=head1 AUTHOR