File Coverage

blib/lib/if.pm
Criterion Covered Total %
statement 16 16 100.0
branch 9 10 90.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 28 29 96.5


line stmt bran cond sub pod time code
1             package if;
2              
3             $VERSION = '0.0606';
4              
5             sub work {
6 7 100   7   14 my $method = shift() ? 'import' : 'unimport';
7 7 100       27 unless (@_ >= 2) {
8 2 100       6 my $type = ($method eq 'import') ? 'use' : 'no';
9 2         27 die "Too few arguments to '$type if' (some code returning an empty list in list context?)"
10             }
11 5 100       57 return unless shift; # CONDITION
12              
13 3         4 my $p = $_[0]; # PACKAGE
14 3         8 (my $file = "$p.pm") =~ s!::!/!g;
15 3         12 require $file; # Works even if $_[0] is a keyword (like open)
16 3         20 my $m = $p->can($method);
17 3 50       68 goto &$m if $m;
18             }
19              
20 6     6   2330 sub import { shift; unshift @_, 1; goto &work }
  6         9  
  6         14  
21 1     1   5 sub unimport { shift; unshift @_, 0; goto &work }
  1         2  
  1         3  
22              
23             1;
24             __END__