| 1 | package first; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | ▶ | use version;our $VERSION = qv('0.0.1'); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | # require UNIVERSAL::require; | ||||||||||||||
| 10 | # until http://rt.cpan.org/Ticket/Display.html?id=24741 is added we'll inlcude it at the end | ||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | our $module; | |||||||||||||
| 13 | 1 | our $failed = {}; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=9 SCAR=38.3
| |||||||||||||||
| 16 | 1 | my $self = shift; | |||||||||||||
| 17 | 0 | my %flags = map { $_ => 1,} grep(/^-/, @_); | |||||||||||||
| 18 | |||||||||||||||
| 19 | 1 | $module = undef; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 1 | local $UNIVERSAL::Level = $UNIVERSAL::Level + 1; # || -level=1 + 1 | |||||||||||||
| 22 | |||||||||||||||
| 23 | 1 | for my $ns (grep !/^-/, @_) { | |||||||||||||
| 24 | 0 | ▶ | next if !defined$ns; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | my $nms = $ns; # copy to possibly modify | |||||||||||||
| 27 | 0 | my @imp; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | if(ref $ns eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 0 | $nms = shift @{ $ns }; | |||||||||||||
| 31 | 0 | @imp = @{ $ns }; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | ▶ | if( @imp ? $nms->use( @imp ) : $nms->use ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 35 | 0 | $module = $nms; | |||||||||||||
| 36 | 0 | last; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | else { | ||||||||||||||
| 39 | 0 | $failed->{ $nms } = $@; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 1 | ▶ | if( keys %{ $failed } ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | my $msg = "Could not load these modules:\n\t" . join("\n\t", keys %{ $failed }) . "\n"; | |||||||||||||
| 45 | 0 | ▶ | carp $msg if exists $flags{'-carp'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | ▶ | croak $msg if exists $flags{'-croak'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 1 | return $module; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | ################################ | ||||||||||||||
| 53 | #### start UNIVERSAL::require ## | ||||||||||||||
| 54 | ################################ | ||||||||||||||
| 55 | |||||||||||||||
| 56 | # UNIVERSAL-require-0.11 | ||||||||||||||
| 57 | # sans POD, and with http://rt.cpan.org/Ticket/Display.html?id=24741 | ||||||||||||||
| 58 | |||||||||||||||
| 59 | package UNIVERSAL::require; | ||||||||||||||
| 60 | 1 | $UNIVERSAL::require::VERSION = '0.11'; | |||||||||||||
| 61 | |||||||||||||||
| 62 | # We do this because UNIVERSAL.pm uses CORE::require(). We're going | ||||||||||||||
| 63 | # to put our own require() into UNIVERSAL and that makes an ambiguity. | ||||||||||||||
| 64 | # So we load it up beforehand to avoid that. | ||||||||||||||
| 65 | 1 | ▶ | BEGIN { require UNIVERSAL } | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | package UNIVERSAL; | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 70 | |||||||||||||||
| 71 | 1 | ▶ | use vars qw($Level); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 72 | 1 | $Level = 0; | |||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | sub require { | ||||||||||||
|
Subroutine
require: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 75 | 0 | my($module, $want_version) = @_; | |||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | $UNIVERSAL::require::ERROR = ''; | |||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ▶ | die("UNIVERSAL::require() can only be run as a class method") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 80 | if ref $module; | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | die("UNIVERSAL::require() takes no or one arguments") if @_ > 2; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | my($call_package, $call_file, $call_line) = caller($Level); | |||||||||||||
| 85 | |||||||||||||||
| 86 | # Load the module. | ||||||||||||||
| 87 | 0 | my $file = $module . '.pm'; | |||||||||||||
| 88 | 0 | $file =~ s{::}{/}g; | |||||||||||||
| 89 | |||||||||||||||
| 90 | # For performance reasons, check if its already been loaded. This makes | ||||||||||||||
| 91 | # things about 4 times faster. | ||||||||||||||
| 92 | 0 | ▶ | return 1 if $INC{$file}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | my $return = eval qq{ | |||||||||||||
| 95 | #line $call_line "$call_file" | ||||||||||||||
| 96 | CORE::require(\$file); | ||||||||||||||
| 97 | }; | ||||||||||||||
| 98 | |||||||||||||||
| 99 | # Check for module load failure. | ||||||||||||||
| 100 | 0 | ▶ | if( $@ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 101 | 0 | $UNIVERSAL::require::ERROR = $@; | |||||||||||||
| 102 | 0 | return $return; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | # Module version check. | ||||||||||||||
| 106 | 0 | ▶ | if( @_ == 2 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | 0 | eval qq{ | |||||||||||||
| 108 | #line $call_line "$call_file" | ||||||||||||||
| 109 | \$module->VERSION($want_version); | ||||||||||||||
| 110 | }; | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | ▶ | if( $@ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 113 | 0 | $UNIVERSAL::require::ERROR = $@; | |||||||||||||
| 114 | 0 | return 0; | |||||||||||||
| 115 | } | ||||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | return $return; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 0 | ▶ | sub use { | ||||||||||||
|
Subroutine
use: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 122 | 0 | my($module, @imports) = @_; | |||||||||||||
| 123 | |||||||||||||||
| 124 | 0 | ▶ | local $Level = $Level ? $Level : 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | 0 | ▶ | my $return = $module->require or return 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | my($call_package, $call_file, $call_line) = caller; | |||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | eval qq{ | |||||||||||||
| 130 | package $call_package; | ||||||||||||||
| 131 | #line $call_line "$call_file" | ||||||||||||||
| 132 | \$module->import(\@imports); | ||||||||||||||
| 133 | }; | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | ▶ | if( $@ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 136 | 0 | $UNIVERSAL::require::ERROR = $@; | |||||||||||||
| 137 | 0 | return 0; | |||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | 0 | return $return; | |||||||||||||
| 141 | } | ||||||||||||||
| 142 | |||||||||||||||
| 143 | ############################## | ||||||||||||||
| 144 | #### end UNIVERSAL::require ## | ||||||||||||||
| 145 | ############################## | ||||||||||||||
| 146 | |||||||||||||||
| 147 | 1 | 1; | |||||||||||||
| 148 | |||||||||||||||
| 149 | __END__ | ||||||||||||||