| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Eponymous::Hash; | 
| 2 | 1 |  |  | 1 |  | 24279 | use PadWalker 'var_name'; | 
|  | 1 |  |  |  |  | 1847 |  | 
|  | 1 |  |  |  |  | 189 |  | 
| 3 | 1 |  |  | 1 |  | 10 | use Scalar::Util 'blessed'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 409 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.02'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | sub import { | 
| 8 | 4 |  |  | 4 |  | 27 | shift; | 
| 9 | 4 |  | 100 |  |  | 19 | my $name = pop || 'eponymous_hash'; | 
| 10 | 4 |  |  |  |  | 8 | my $calling_class = caller; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 4 |  |  |  |  | 7 | *{"${calling_class}::$name"} = \&eponymous_hash; | 
|  | 4 |  |  |  |  | 2601 |  | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub eponymous_hash { | 
| 16 | 4 | 100 |  | 4 | 1 | 4884 | if (ref $_[0] eq 'HASH') { | 
|  |  | 100 |  |  |  |  |  | 
| 17 | 1 |  |  |  |  | 3 | return map {$_ => $_[0]->{$_}} @_[1..$#_]; | 
|  | 2 |  |  |  |  | 10 |  | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  | elsif (blessed $_[0]) { | 
| 20 | 1 |  |  |  |  | 5 | return map {$_ => $_[0]->$_} @_[1..$#_]; | 
|  | 2 |  |  |  |  | 9 |  | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  | else { | 
| 23 | 2 |  |  |  |  | 4 | return map { substr(var_name(1, \$_), 1) => $_ } @_; | 
|  | 4 |  |  |  |  | 35 |  | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | 1; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =head1 NAME | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | Eponymous::Hash - Translates named variables to a hash list with corresponding keys | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Translates named variables to a hash list with corresponding keys | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head1 USAGE | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | use Eponymous::Hash 'epy'; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | The name 'epy' is arbitrary. You may define any name in the use statement. | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | B | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | my $mammal = 'ponycorn'; | 
| 46 |  |  |  |  |  |  | my $diet   = 'sprinkles'; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | my %hash = epy($mammal, $diet) | 
| 49 |  |  |  |  |  |  | # (mammal => 'ponycorn', diet => 'sprinkles') | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | B | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | my $thing = { | 
| 55 |  |  |  |  |  |  | mammal => 'ponycorns', | 
| 56 |  |  |  |  |  |  | diet => 'sprinkls' | 
| 57 |  |  |  |  |  |  | }; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | my %hash = epy($thing, 'mammal', 'diet'); | 
| 60 |  |  |  |  |  |  | # (mammal => 'ponycorn', diet => 'sprinkles') | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | B | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | my $thing = Thing->new; | 
| 66 |  |  |  |  |  |  | $thing->mammal; # ponycorns | 
| 67 |  |  |  |  |  |  | $thing->diet;   # sprinkles | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | my %hash = epy($thing, 'mammal', 'diet'); | 
| 70 |  |  |  |  |  |  | # (mammal => 'ponycorn', diet => 'sprinkles') | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head1 METHODS | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head2 eponymous_hash | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Default method name.  If parameter is passed to use statement, parameter will be used instead. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 VERSION | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | 0.02 | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head1 AUTHOR | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Glen Hinkle C |