File Coverage

blib/lib/if.pm
Criterion Covered Total %
statement 11 14 78.5
branch 5 8 62.5
condition n/a
subroutine 2 3 66.6
pod n/a
total 18 25 72.0


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