Rose-Object
view release on metacpan or search on metacpan
lib/Rose/Object/MixIn.pm view on Meta::CPAN
package Rose::Object::MixIn;
use strict;
use Carp;
our $Debug = 0;
our $VERSION = '0.856';
use Rose::Class::MakeMethods::Set
(
inheritable_set =>
[
'_export_tag' =>
{
list_method => '_export_tags',
clear_method => 'clear_export_tags',
add_method => '_add_export_tag',
delete_method => 'delete_export_tag',
deletes_method => 'delete_export_tags',
},
'_pre_import_hook',
{
clear_method => 'clear_pre_import_hooks',
add_method => 'add_pre_import_hook',
adds_method => 'add_pre_import_hooks',
delete_method => 'delete_pre_import_hook',
deletes_method => 'delete_pre_import_hooks',
},
],
);
sub import
{
my($class) = shift;
my $target_class = (caller)[0];
my($force, @methods, %import_as);
foreach my $arg (@_)
{
if(!defined $target_class && $arg !~ /^-/)
{
$target_class = $arg;
next;
}
if($arg =~ /^-?-force$/)
{
$force = 1;
}
elsif($arg =~ /^-?-target[-_]class$/)
{
$target_class = undef; # set on next iteration...lame
next;
}
elsif($arg =~ /^:(.+)/)
{
my $methods = $class->export_tag($1) or
croak "Unknown export tag - '$arg'";
push(@methods, @$methods);
}
elsif(ref $arg eq 'HASH')
{
while(my($method, $name) = each(%$arg))
{
push(@methods, $method);
$import_as{$method} = $name;
}
}
else
{
push(@methods, $arg);
}
}
foreach my $method (@methods)
{
my $code = $class->can($method) or
croak "Could not import method '$method' from $class - no such method";
my $import_as = $import_as{$method} || $method;
if($target_class->can($import_as) && !$force)
{
croak "Could not import method '$import_as' from $class into ",
"$target_class - a method by that name already exists. ",
"Pass a '-force' argument to import() to override ",
"existing methods."
}
if(my $hooks = $class->pre_import_hooks($method))
{
foreach my $code (@$hooks)
{
( run in 1.572 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )