| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Acme::Damn; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 117948 | use 5.000; | 
|  | 6 |  |  |  |  | 17 |  | 
|  | 6 |  |  |  |  | 187 |  | 
| 4 | 6 |  |  | 6 |  | 23 | use strict; | 
|  | 6 |  |  |  |  | 6 |  | 
|  | 6 |  |  |  |  | 147 |  | 
| 5 | 6 |  |  | 6 |  | 20 | use warnings; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 161 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 6 |  |  | 6 |  | 22 | use Exporter; | 
|  | 6 |  |  |  |  | 6 |  | 
|  | 6 |  |  |  |  | 239 |  | 
| 8 | 6 |  |  | 6 |  | 24 | use DynaLoader  qw( AUTOLOAD ); | 
|  | 6 |  |  |  |  | 7 |  | 
|  | 6 |  |  |  |  | 150 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 6 |  |  | 6 |  | 21 | use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK ); | 
|  | 6 |  |  |  |  | 4 |  | 
|  | 6 |  |  |  |  | 1531 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | $VERSION    = '0.06'; | 
| 13 |  |  |  |  |  |  | @ISA        = qw( Exporter DynaLoader ); | 
| 14 |  |  |  |  |  |  | @EXPORT     = qw( damn                ); | 
| 15 |  |  |  |  |  |  | @EXPORT_OK  = qw( bless               ); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | # ensure we aren't exposed to changes in inherited AUTOLOAD behaviour | 
| 18 |  |  |  |  |  |  | *Acme::Damn::AUTOLOAD   = *DynaLoader::AUTOLOAD; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub import | 
| 22 |  |  |  |  |  |  | { | 
| 23 | 9 |  |  | 9 |  | 1068 | my  $class    = shift; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # check the unknown symbols to ensure they are 'safe' | 
| 26 | 9 |  |  |  |  | 15 | my  @bad      = grep { /\W/o } @_; | 
|  | 26 |  |  |  |  | 47 |  | 
| 27 | 9 | 100 |  |  |  | 25 | if ( @bad ) { | 
| 28 |  |  |  |  |  |  | # throw an error message informing the user where the problem is | 
| 29 | 3 |  |  |  |  | 7 | my  ( undef, $file , $line )    = caller 0; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 3 |  |  |  |  | 28 | die sprintf( "Bad choice of symbol name%s %s for import at %s line %s\n" | 
| 32 |  |  |  |  |  |  | , ( @bad == 1 ) ? '' : 's' | 
| 33 | 3 | 50 |  |  |  | 102 | , join( ', ' , map { qq|'$_'| } @bad ) , $file , $line ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # remove duplicates from the list of aliases, as well as those symbol | 
| 37 |  |  |  |  |  |  | # names listed in @EXPORT | 
| 38 |  |  |  |  |  |  | #   - we keep @EXPORT_OK in a separate list since they are optionally | 
| 39 |  |  |  |  |  |  | #     requested at use() time | 
| 40 | 6 |  |  |  |  | 7 | my  @aliases  = do {  local %_; | 
|  | 6 |  |  |  |  | 9 |  | 
| 41 | 6 |  |  |  |  | 17 | @_{ @_         } = undef; | 
| 42 | 6 |  |  |  |  | 12 | delete @_{ @EXPORT    }; | 
| 43 | 6 |  |  |  |  | 18 | keys %_ | 
| 44 |  |  |  |  |  |  | }; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # 'import' the symbols into the host package | 
| 47 |  |  |  |  |  |  | #   - ensure 'EXPORT_OK' is correctly honoured | 
| 48 | 6 |  |  |  |  | 9 | my    %reserved   = map { $_ => 1 } @EXPORT , @EXPORT_OK; | 
|  | 12 |  |  |  |  | 25 |  | 
| 49 | 6 |  |  |  |  | 7 | my    @reserved   = (); | 
| 50 | 6 |  |  |  |  | 29 | my  ( $pkg )      = caller 1; | 
| 51 | 6 |  |  |  |  | 73 | foreach my $alias ( @aliases ) { | 
| 52 |  |  |  |  |  |  | # if this alias is a reserved symbol as defined by @EXPORT et al. | 
| 53 |  |  |  |  |  |  | # then add it to the list of symbols to export | 
| 54 | 21 | 100 | 66 |  |  | 44 | $reserved{ $alias } | 
| 55 |  |  |  |  |  |  | and push @reserved , $alias | 
| 56 |  |  |  |  |  |  | and next; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # otherwise, create an alias for 'damn' | 
| 59 | 6 |  |  | 6 |  | 24 | no strict 'refs'; | 
|  | 6 |  |  |  |  | 7 |  | 
|  | 6 |  |  |  |  | 885 |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 20 |  |  |  |  | 54 | *{ $pkg . '::' . $alias } = sub { | 
| 62 | 30 |  |  | 30 |  | 15751 | my    $ref                      = shift; | 
| 63 | 30 |  |  |  |  | 70 | my  ( undef , $file , $line )   = caller 1; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | # call damn() with the location of where this method was | 
| 66 |  |  |  |  |  |  | # originally called | 
| 67 | 30 |  |  |  |  | 1586 | &{ __PACKAGE__ . '::damn' }( $ref , $alias , $file , $line ); | 
|  | 30 |  |  |  |  | 224 |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # NB: wanted to do something like | 
| 70 |  |  |  |  |  |  | #         goto \&{ __PACKAGE__ . '::damn' }; | 
| 71 |  |  |  |  |  |  | #     having set the @_ array appropriately, but this caused a | 
| 72 |  |  |  |  |  |  | #     "Attempt to free unrefernced SV" error that I couldn't solve | 
| 73 |  |  |  |  |  |  | #     - I think it was to do with the @_ array | 
| 74 | 20 |  |  |  |  | 32 | }; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | # add the known symbols to @_ | 
| 78 | 6 |  |  |  |  | 13 | splice @_ , 0;  push @_ , $class , @reserved; | 
|  | 6 |  |  |  |  | 11 |  | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | # run the "proper" import() routine | 
| 81 | 6 |  |  |  |  | 3616 | goto \&Exporter::import; | 
| 82 |  |  |  |  |  |  | } # import() | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | bootstrap Acme::Damn $VERSION; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | 1;  # end of module | 
| 89 |  |  |  |  |  |  | __END__ |