File Coverage

lib/Perlmazing/Engine/Exporter.pm
Criterion Covered Total %
statement 46 77 59.7
branch 10 34 29.4
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 64 120 53.3


line stmt bran cond sub pod time code
1             package Perlmazing::Engine::Exporter;
2 50     50   368 use strict;
  50         93  
  50         1734  
3 50     50   270 use warnings;
  50         103  
  50         1597  
4 50     50   258 use Carp;
  50         102  
  50         6842  
5             our $VERSION = '1.2810';
6             my $package = __PACKAGE__;
7             my $imports;
8            
9             sub import {
10 2068     2068   3466 my $self = shift;
11 2068         17030 my @call = caller 0;
12 2068         4076 my $pack = $call[0];
13 50     50   324 no strict 'refs';
  50         98  
  50         15494  
14 2068 100       4391 if ($self eq $package) {
15 50         91 my $in_isa = grep { /^\Q$package\E$/ } @{"${pack}::ISA"};
  0         0  
  50         300  
16 50 50       194 unshift (@{"${pack}::ISA"}, __PACKAGE__) unless $in_isa;
  50         1607  
17             } else {
18 2018 50       15432 if (my @call = caller 1) {
19 2018 50       5818 $pack = $call[0] if $call[3] eq "${self}::import";
20             }
21 2018 50       6354 return if $imports->{$pack}->{$self};
22 2018         2715 for my $i (@{"${self}::EXPORT"}) {
  2018         5103  
23 185564         298198 $package->export($self, $i, $pack);
24             }
25 2018         349795 $imports->{$pack}->{$self}++;
26             }
27             }
28            
29             sub export {
30 185564     185564 0 212043 my $self = shift;
31 185564         262987 my ($from, $symbol, $to) = (shift, shift, shift);
32 185564         191457 my $sigil = '&';
33 185564         287348 $symbol =~ s/^(\&|\$|\%|\@|\*)/$sigil = $1; ''/e;
  0         0  
  0         0  
34 185564 50       318112 croak "Unknown symbol type for expression '$symbol' in EXPORT" if $symbol =~ /^\W/;
35 50     50   350 no strict 'refs';
  50         103  
  50         1821  
36 50     50   277 no warnings 'once';
  50         98  
  50         19693  
37 185564 50       253332 if ($sigil eq '&') {
    0          
    0          
    0          
    0          
38 185564 50       181615 if (not defined *{"${from}::$symbol"}{CODE}) {
  185564         418526  
39 0         0 eval "sub ${from}::$symbol"; ## no critic
40 0 0       0 croak "Cannot create symbol for sub ${from}::$symbol: $@" if $@;
41             }
42 185564 50       206121 if (defined *{"${to}::$symbol"}{CODE}) {
  185564         633324  
43 0         0 croak "Cannot define symbol &${to}::$symbol: symbol is already defined under the same namespace and name";
44             } else {
45 185564         209944 *{"${to}::$symbol"} = *{"${from}::$symbol"}{CODE};
  185564         484922  
  185564         297397  
46             }
47             } elsif ($sigil eq '$') {
48 0 0         if (not defined *{"${from}::$symbol"}{SCALAR}) {
  0            
49 0           ${"${from}::$symbol"} = undef;
  0            
50             }
51 0           *{"${to}::$symbol"} = *{"${from}::$symbol"}{SCALAR};
  0            
  0            
52             } elsif ($sigil eq '@') {
53 0 0         if (not defined *{"${from}::$symbol"}{ARRAY}) {
  0            
54 0           @{"${from}::$symbol"} = ();
  0            
55             }
56 0           *{"${to}::$symbol"} = *{"${from}::$symbol"}{ARRAY};
  0            
  0            
57             } elsif ($sigil eq '%') {
58 0 0         if (not defined *{"${from}::$symbol"}{HASH}) {
  0            
59 0           %{"${from}::$symbol"} = ();
  0            
60             }
61 0           *{"${to}::$symbol"} = *{"${from}::$symbol"}{HASH};
  0            
  0            
62             } elsif ($sigil eq '*') {
63 0           *{"${to}::$symbol"} = *{"${from}::$symbol"};
  0            
  0            
64             } else {
65 0           croak "I don't know how to handle '$symbol' in EXPORT";
66             }
67             }
68            
69             1;