| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package bitflag; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 65844 | use 5.008007; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 90 |  | 
| 4 | 2 |  |  | 2 |  | 12 | use strict; | 
|  | 2 |  |  |  |  | 37 |  | 
|  | 2 |  |  |  |  | 165 |  | 
| 5 | 2 |  |  | 2 |  | 11 | use warnings; | 
|  | 2 |  |  |  |  | 9 |  | 
|  | 2 |  |  |  |  | 213 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | require Exporter; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our @EXPORT_OK = qw ( getmask ); | 
| 12 |  |  |  |  |  |  | our @EXPORT = qw( ); | 
| 13 |  |  |  |  |  |  | our $VERSION = 0.01; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 12 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1218 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | my ($caller,%FLAGMAP); | 
| 18 |  |  |  |  |  |  | my ($igcase,$mask) = (0,1); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub import | 
| 21 |  |  |  |  |  |  | { | 
| 22 | 7 |  |  | 7 |  | 1221 | my $class = shift; | 
| 23 | 7 | 100 |  |  |  | 32 | return unless @_; | 
| 24 | 6 |  |  |  |  | 88 | $caller = caller; # i.e. = caller[0] | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | #    print "bitflag::import from caller $caller\n"; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 6 |  |  |  |  | 10 | my ($head) = @_; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # begin optiomally assign $igcase,$mask using an options hash as first argument | 
| 31 | 6 | 100 |  |  |  | 15 | if ( ref($head) eq 'HASH' ) | 
| 32 |  |  |  |  |  |  | { | 
| 33 | 3 | 100 |  |  |  | 9 | $igcase = $head->{ic} if exists $head->{ic}; | 
| 34 | 3 | 50 |  |  |  | 9 | $head->{sm} = delete $head->{startmask}  if exists $head->{startmask}; | 
| 35 | 3 | 100 |  |  |  | 17 | $mask = $head->{sm} if exists $head->{sm}; | 
| 36 | 3 |  |  |  |  | 5 | shift; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | else | 
| 39 |  |  |  |  |  |  | #   or only $mask simply with a numeric first argument | 
| 40 |  |  |  |  |  |  | { | 
| 41 | 3 | 100 |  |  |  | 26 | if ($head =~ qr{\A\d+\Z}) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 1 |  |  |  |  | 3 | $mask = shift  ; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | # end   optiomally assign ... | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 6 |  |  |  |  | 14 | foreach my $flagname (@_) | 
| 49 |  |  |  |  |  |  | { | 
| 50 | 21 |  |  | 0 |  | 141 | *{$caller.'::'.$flagname} = sub () {$mask}; | 
|  | 21 |  |  |  |  | 108 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 51 | 21 | 50 |  |  |  | 48 | my $flagalias = $igcase ? lc($flagname) : $flagname; | 
| 52 | 21 |  |  |  |  | 39 | $FLAGMAP{$flagalias} = $mask; | 
| 53 | 21 |  |  |  |  | 37 | $mask <<= 1 | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | #    $class->export_to_level(2,$class,'getmask'); | 
| 57 | 2 |  |  |  |  | 67 | *{$caller.'::getmask'} = | 
| 58 |  |  |  |  |  |  | sub | 
| 59 |  |  |  |  |  |  | { | 
| 60 | 13 |  |  | 13 |  | 7298 | my $r = 0; | 
| 61 | 13 |  |  |  |  | 30 | foreach my $v (@_) | 
| 62 |  |  |  |  |  |  | { | 
| 63 | 32 | 50 |  |  |  | 69 | my $vkey = $igcase ? lc($v) : $v; | 
| 64 | 32 | 100 |  |  |  | 62 | if ( exists $FLAGMAP{$vkey} ) | 
| 65 |  |  |  |  |  |  | { | 
| 66 | 30 |  |  |  |  | 68 | $r |= $FLAGMAP{$vkey}; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | else | 
| 69 |  |  |  |  |  |  | { | 
| 70 | 2 |  |  |  |  | 137 | warn "unknown flagname: $v\n"; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  | $r | 
| 74 | 13 |  |  |  |  | 29 | } | 
| 75 | 6 | 100 |  |  |  | 11 | unless defined *{$caller.'::getmask'}; | 
|  | 6 |  |  |  |  | 156 |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 1; | 
| 80 |  |  |  |  |  |  | __END__ |