File Coverage

blib/lib/Package/Relative.pm
Criterion Covered Total %
statement 26 31 83.8
branch 6 6 100.0
condition n/a
subroutine 7 9 77.7
pod 3 3 100.0
total 42 49 85.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Package::Relative;
4              
5 1     1   21137 use strict;
  1         2  
  1         34  
6 1     1   5 use warnings;
  1         2  
  1         47  
7              
8             our $VERSION = "0.01";
9              
10             use overload (
11 1         7 '""' => 'stringify',
12             '.' => 'concat',
13             fallback => 1,
14 1     1   1708 );
  1         1146  
15              
16             our @EXPORT = qw/PKG/;
17 1     1   97 use base qw/Exporter/;
  1         2  
  1         404  
18              
19             sub PKG {
20 9     9 1 459 my $caller = caller;
21 9         46 return bless \$caller, __PACKAGE__;
22             }
23              
24             sub stringify {
25 9     9 1 80 ${ $_[0] };
  9         97  
26             }
27              
28             sub concat {
29 7     7 1 12 my $self = shift;
30 7         8 my $other = shift;
31 7         8 my $reversed = shift;
32              
33 7 100       18 ($self, $other) = ($other, $self) if $reversed;
34              
35 7         14 my @pkg = grep { length } split '::', "$self";
  20         34  
36            
37 7 100       21 /^\.\.$/ ? pop @pkg : push @pkg, $_ for (grep { length } split '::', "$other");
  17         80  
38              
39 7         18 my $pkg = join("::", @pkg);
40              
41 7 100       40 $reversed ? bless \$pkg, __PACKAGE__ : $pkg;
42             }
43              
44             sub AUTOLOAD {
45 0     0     my $self = shift;
46 0           my $pkg = $self->stringify;
47              
48             # FIXME: perhaps this should croak? After all, without concatenating you might as well use __PACKAGE__
49              
50 0           my ($method) = (our $AUTOLOAD =~ /:([^:]+)$/);
51              
52 0           $pkg->$method(@_);
53             }
54              
55 0     0     sub DESTROY {}
56              
57             __PACKAGE__
58              
59             __END__