| 1 | # To do: | ||||||||||||||||||||||||||||
| 2 | # - Turn die to croak (with tests) | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | package perl5; | ||||||||||||||||||||||||||||
| 6 | 10 | our $VERSION = '0.21'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 10 | my $requested_perl_version = 0; | |||||||||||||||||||||||||||
| 12 | 10 | my $perl_version = 10; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 14 | ▶ | sub VERSION { | ||||||||||||||||||||||||||
|
Subroutine
VERSION: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 14 | my ($class, $version) = @_; | |||||||||||||||||||||||||||
| 16 | 14 | $version = version->parse($version); | |||||||||||||||||||||||||||
| 17 | 14 | ▶ | if ($version < 10) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 2 | my $this_version = do { | |||||||||||||||||||||||||||
| 19 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | version->parse(${$class . '::VERSION'}); | |||||||||||||||||||||||||||
| 21 | }; | ||||||||||||||||||||||||||||
| 22 | 2 | ▶ | if ($version > $this_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 2 | Carp::croak( | |||||||||||||||||||||||||||
| 24 | "$class version $version required" . | ||||||||||||||||||||||||||||
| 25 | "--this is only version $this_version" | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | else { | ||||||||||||||||||||||||||||
| 30 | 12 | $requested_perl_version = $version; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 37 | ▶ | sub version_check { | ||||||||||||||||||||||||||
|
Subroutine
version_check: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 37 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 37 | ▶ | if (defined $args->[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 28 | my $version = $args->[0]; | |||||||||||||||||||||||||||
| 39 | 28 | $version =~ s/^-//; | |||||||||||||||||||||||||||
| 40 | 28 | ▶ | if (version::is_lax($version) and version->parse($version) >= 10) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
version::is_lax($version) and "version"->parse($version) >= 10
MC/DC50%1/2
version::is_lax($version) and "version"->parse($version) >= 10
version::is_lax($version)
"version"->parse($version) >= 10
Truth table66%2/3
A and B
A= version::is_lax($version)B= "version"->parse($version) >= 10
| |||||||||||||||||||||||||||||
| 41 | 15 | $requested_perl_version = version->parse($version); | |||||||||||||||||||||||||||
| 42 | 15 | shift(@$args); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 37 | ▶ | if ($requested_perl_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 27 | my $version = $requested_perl_version->numify / 1000 + 5; | |||||||||||||||||||||||||||
| 47 | 27 | $perl_version = $requested_perl_version; | |||||||||||||||||||||||||||
| 48 | 27 | $requested_perl_version = 0; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | eval "use $version"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||
| 50 | 27 | ▶ | do { Carp::croak($@) } if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 37 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=20.9
| |||||||||||||||||||||||||||||
| 55 | 37 | ▶ | return unless @_; # XXX not sure why | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 37 | my $class = shift; | |||||||||||||||||||||||||||
| 57 | 37 | $class->version_check(\@_); | |||||||||||||||||||||||||||
| 58 | 26 | my $arg = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 26 | ▶ | if ($class ne 'perl5') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | (my $usage = $class) =~ s/::/-/; | |||||||||||||||||||||||||||
| 62 | 0 | die "Don't 'use $class'. Try 'use $usage'"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 26 | ▶ | die "Too many arguments for 'use perl5...'" if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 26 | ▶ | my $subclass = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 67 | not(defined($arg)) ? __PACKAGE__ : | ||||||||||||||||||||||||||||
| 68 | $arg =~ /^-(\w+)$/ ?__PACKAGE__ . "::$1" : | ||||||||||||||||||||||||||||
| 69 | die "'$arg' is an invalid first argument to 'use perl5...'"; | ||||||||||||||||||||||||||||
| 70 | 26 | ▶ | eval "require $subclass; 1" or die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 26 | @_ = ($subclass); | |||||||||||||||||||||||||||
| 73 | 26 | goto &{$class->can('importer')}; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 26 | ▶ | sub importer { | ||||||||||||||||||||||||||
|
Subroutine
importer: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 26 | my $class = shift; | |||||||||||||||||||||||||||
| 78 | 26 | ▶ | my @imports = scalar(@_) ? @_ : $class->imports; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 26 | my $caller = caller(0); # maybe allow 'use perl5-foo package=>Bar'? | |||||||||||||||||||||||||||
| 81 | 26 | my $important = eval "package $caller; my \$sub = sub { shift->import(\@_) };"; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 26 | ▶ | while (@imports) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 68 | my $name = shift(@imports); | |||||||||||||||||||||||||||
| 85 | 68 | ▶ | my $version = (@imports and version::is_lax($imports[0])) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@imports and version::is_lax($imports[0])
MC/DC100%2/2
@imports and version::is_lax($imports[0])
@imports
version::is_lax($imports[0])
Truth table100%3/3
A and B
A= @importsB= version::is_lax($imports[0])
| |||||||||||||||||||||||||||||
| 86 | ? version->parse(shift(@imports))->numify : ''; | ||||||||||||||||||||||||||||
| 87 | 68 | ▶ | my $arguments = (@imports and ref($imports[0]) eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@imports and ref $imports[0] eq "ARRAY"
MC/DC100%2/2
@imports and ref $imports[0] eq "ARRAY"
@imports
ref $imports[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @importsB= ref $imports[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 88 | ? shift(@imports) : []; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 68 | ▶ | eval "require $name; 1" or die $@; # could be improved | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 67 | ▶ | $name->VERSION($version) if $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 66 | $name->$important(@$arguments); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # goto &$important; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 20 | ▶ | sub imports { | ||||||||||||||||||||||||||
|
Subroutine
imports: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 20 | my $subversion = int($perl_version); | |||||||||||||||||||||||||||
| 100 | return ( | ||||||||||||||||||||||||||||
| 101 | 20 | 'strict', | |||||||||||||||||||||||||||
| 102 | 'warnings', | ||||||||||||||||||||||||||||
| 103 | 'feature' => [":5.$subversion"], | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 10 | 1; | |||||||||||||||||||||||||||