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.0608';
4              
5             sub work {
6 11 100   11   28 my $method = shift() ? 'import' : 'unimport';
7 11 100       26 unless (@_ >= 2) {
8 2 100       4 my $type = ($method eq 'import') ? 'use' : 'no';
9 2         43 die "Too few arguments to '$type if' (some code returning an empty list in list context?)"
10             }
11 9 100       69 return unless shift; # CONDITION
12              
13 6         7 my $p = $_[0]; # PACKAGE
14 6         15 (my $file = "$p.pm") =~ s!::!/!g;
15 6         1565 require $file; # Works even if $_[0] is a keyword (like open)
16 6         4825 my $m = $p->can($method);
17 6 50       1476 goto &$m if $m;
18             }
19              
20 9     9   6999 sub import { shift; unshift @_, 1; goto &work }
  9         16  
  9         24  
21 2     2   17 sub unimport { shift; unshift @_, 0; goto &work }
  2         4  
  2         7  
22              
23             1;
24             __END__