File Coverage

blib/lib/autopackage.pm
Criterion Covered Total %
statement 22 22 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 30 31 96.7


line stmt bran cond sub pod time code
1             package autopackage;
2             {
3             $autopackage::VERSION = '0.01';
4             }
5 1     1   1252 use strict;
  1         2  
  1         39  
6 1     1   5 use warnings;
  1         2  
  1         41  
7              
8             # ABSTRACT: Automatically set your package based on how your module was loaded.
9              
10              
11 1     1   820 use B::Hooks::Parser 0.08 qw();
  1         3670  
  1         31  
12 1     1   8 use Carp 0 qw(confess);
  1         18  
  1         247  
13              
14             sub import {
15              
16             # figure out where we're called from
17 1     1   10 my (undef, $filename) = caller(0);
18              
19             # figure out where it got loaded via %INC.
20 1         3 my $pkg;
21 1         74 for my $k (sort keys %INC)
22             {
23 48 100       107 if ($INC{$k} eq $filename)
24             {
25 1         2 $pkg = $k;
26 1         6 $pkg =~ s<[/\\]><::>g;
27 1         4 $pkg =~ s<\.pm$><>i; # can this be uppercase on some platforms?
28 1         2 last;
29             }
30             }
31              
32 1 50       8 confess("autopackage could not determine package for filename '$filename', died")
33             unless defined $pkg;
34              
35 1         5 B::Hooks::Parser::inject("; package $pkg;");
36             };
37              
38             1;
39              
40             __END__