Rose-HTML-Objects
view release on metacpan or search on metacpan
lib/Rose/HTML/Object/Exporter.pm view on Meta::CPAN
package Rose::HTML::Object::Exporter;
use strict;
use Carp;
our $VERSION = '0.605';
our $Debug = 0;
use Rose::Class::MakeMethods::Generic
(
inheritable_hash =>
[
export_tags => { interface => 'get_set_all', hash_key => 'export_tags' },
_export_tag => { interface => 'get_set', hash_key => 'export_tags' },
clear_export_tags => { interface => 'clear', hash_key => 'export_tags' },
delete_export_tags => { interface => 'delete', hash_key => 'export_tags' },
_pre_import_hooks => { interface => 'get_set_all', hash_key => 'pre_import_hooks' },
_pre_import_hook => { interface => 'get_set', hash_key => 'pre_import_hooks' },
clear_pre_import_hooks => { interface => 'clear', hash_key => 'pre_import_hooks' },
delete_pre_import_hooks => { interface => 'delete', hash_key => 'pre_import_hooks' },
],
);
our %Imported;
sub imported
{
my($class, $symbol) = (shift, shift);
if(@_)
{
return $Imported{$class}{$symbol}{'from'} = shift;
}
return $Imported{$class}{$symbol};
}
our $Target_Class;
sub import
{
my($class) = shift;
my $target_class = $Target_Class || (caller)[0];
my($force, @symbols, %import_as, $imported);
foreach my $arg (@_)
{
if($arg =~ /^-?-force$/)
{
$force = 1;
}
elsif($arg =~ /^:(.+)/)
{
my $symbols = $class->export_tag($1) or
croak "Unknown export tag - '$arg'";
push(@symbols, @$symbols);
}
elsif(ref $arg eq 'HASH')
{
while(my($symbol, $name) = each(%$arg))
{
push(@symbols, $symbol);
$import_as{$symbol} = $name;
}
}
else
{
push(@symbols, $arg);
}
}
foreach my $symbol (@symbols)
{
my $code = $class->can($symbol) or
croak "Could not import symbol '$symbol' from $class into $target_class - no such symbol";
my $is_constant = (defined prototype($code) && !length(prototype($code))) ? 1 : 0;
my $import_as = $import_as{$symbol} || $symbol;
my $existing_code = $target_class->can($import_as);
no strict 'refs';
no warnings 'uninitialized';
if($existing_code && !$force && (
($is_constant && $existing_code eq \&{"${target_class}::$import_as"}) ||
(!$is_constant && $existing_code)))
{
next if($Imported{$target_class}{$import_as});
croak "Could not import symbol '$import_as' from $class into ",
"$target_class - a symbol by that name already exists. ",
"Pass a '--force' argument to import() to override ",
"existing symbols."
}
if(my $hooks = $class->pre_import_hooks($symbol))
{
foreach my $code (@$hooks)
{
( run in 0.663 second using v1.01-cache-2.11-cpan-5735350b133 )