| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package # this is an example for install_subroutine()/uninstall_subroutine(). | 
| 2 |  |  |  |  |  |  | Sub::Exporter::Lexical; | 
| 3 | 2 |  |  | 2 |  | 37959 | use 5.008_001; | 
|  | 2 |  |  |  |  | 5 |  | 
| 4 | 2 |  |  | 2 |  | 8 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 27 |  | 
| 5 | 2 |  |  | 2 |  | 6 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 39 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 635 | use Data::Util; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 73 |  | 
| 8 | 2 |  |  | 2 |  | 8 | use Carp (); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 516 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub import :method{ | 
| 11 | 2 |  |  | 2 |  | 18 | my $class    = shift; | 
| 12 | 2 |  |  |  |  | 4 | my $exportee = caller; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 2 |  |  |  |  | 28 | $class->setup_installer($exportee, @_); | 
| 15 |  |  |  |  |  |  | } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub setup_installer :method{ | 
| 18 | 2 |  |  | 2 | 0 | 5 | my($exporter, $exportee, %args) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 2 |  |  |  |  | 18 | my $exportable_ref = Data::Util::mkopt_hash $args{exports}, 'setup', 'CODE'; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 2 |  |  |  |  | 3 | while(my($name, $entity) = each %{$exportable_ref}){ | 
|  | 8 |  |  |  |  | 20 |  | 
| 23 | 6 | 100 |  |  |  | 9 | unless($entity){ | 
| 24 | 2 |  |  |  |  | 15 | $exportable_ref->{$name} = Data::Util::get_code_ref($exportee, $name, -create); | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | Data::Util::install_subroutine($exportee, import => sub :method{ | 
| 29 | 2 |  |  | 2 |  | 43 | my $class = shift; | 
|  |  |  |  | 1 |  |  |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 2 |  |  |  |  | 1 | my $export_ref; | 
| 32 | 2 | 50 |  |  |  | 5 | if(@_){ | 
| 33 | 0 |  |  |  |  | 0 | $export_ref = {}; | 
| 34 | 0 |  |  |  |  | 0 | for my $name(@_){ | 
| 35 | 0 | 0 |  |  |  | 0 | $export_ref->{$name} = $exportable_ref->{$name} | 
| 36 |  |  |  |  |  |  | or Carp::croak "$name is not exportable in $exportee"; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | else{ | 
| 41 | 2 |  |  |  |  | 2 | $export_ref = $exportable_ref; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 2 |  |  |  |  | 5 | my $into = caller; | 
| 45 | 2 |  |  |  |  | 22 | Data::Util::install_subroutine($into, %{$export_ref}); | 
|  | 2 |  |  |  |  | 10 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 2 |  |  |  |  | 4 | $^H |= 0x020000; # HINT_LOCALIZE_HH | 
| 48 | 2 |  | 50 |  |  | 27 | my $cleaner = $^H{$exporter .'/'. $into} ||= bless [$into], $exporter; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 2 |  |  |  |  | 2 | push @{$cleaner}, %{$export_ref}; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 6 |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 2 |  |  |  |  | 171 | return; | 
| 53 | 2 |  |  |  |  | 49 | }); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub DESTROY :method{ | 
| 57 | 2 |  |  | 2 |  | 4 | my($self) = @_; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 2 |  |  |  |  | 2 | Data::Util::uninstall_subroutine(@{$self}); | 
|  | 2 |  |  |  |  | 1101 |  | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | 1; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | __END__ |