| 1 | # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | # vim:ts=8:sw=2:et:sta:sts=2:tw=78 | ||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Module::Metadata; # git description: v1.000039-4-gc6c006f | ||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Gather package and POD information from perl module files | ||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Adapted from Perl-licensed code originally distributed with | ||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Module-Build by Ken Williams | ||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | # This module provides routines to gather information about | ||||||||||||||||||||||||||||||||||||||||||||
| 10 | # perl modules (assuming this may be expanded in the distant | ||||||||||||||||||||||||||||||||||||||||||||
| 11 | # parrot future to look at other types of modules). | ||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 115 | ▶ | sub __clean_eval { eval $_[0] } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__clean_eval: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | our $VERSION = '1.000040'; | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Try really hard to not depend ony any DynaLoaded module, such as IO::File or Fcntl | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | eval { | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | require Fcntl; Fcntl->import('SEEK_SET'); 1; | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | } or *SEEK_SET = sub { 0 } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 10 | ▶ | use version 0.87; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | ▶ | if ($INC{'Log/Contextual.pm'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | require "Log/Contextual/WarnLogger.pm"; # Hide from AutoPrereqs | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | Log::Contextual->import('log_info', | |||||||||||||||||||||||||||||||||||||||||||
| 32 | '-default_logger' => Log::Contextual::WarnLogger->new({ env_prefix => 'MODULE_METADATA', }), | ||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | ▶ | *log_info = sub (&) { warn $_[0]->() }; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | use File::Find qw(find); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | my $V_NUM_REGEXP = qr{v?[0-9._]+}; # crudely, a v-string or decimal | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | my $PKG_FIRST_WORD_REGEXP = qr{ # the FIRST word in a package name | |||||||||||||||||||||||||||||||||||||||||||
| 44 | [a-zA-Z_] # the first word CANNOT start with a digit | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | (?: | ||||||||||||||||||||||||||||||||||||||||||||
| 46 | [\w']? # can contain letters, digits, _, or ticks | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | \w # But, NO multi-ticks or trailing ticks | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | )* | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my $PKG_ADDL_WORD_REGEXP = qr{ # the 2nd+ word in a package name | |||||||||||||||||||||||||||||||||||||||||||
| 52 | \w # the 2nd+ word CAN start with digits | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | (?: | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | [\w']? # and can contain letters or ticks | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | \w # But, NO multi-ticks or trailing ticks | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | )* | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | my $PKG_NAME_REGEXP = qr{ # match a package name | |||||||||||||||||||||||||||||||||||||||||||
| 60 | (?: :: )? # a pkg name can start with arisdottle | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | $PKG_FIRST_WORD_REGEXP # a package word | ||||||||||||||||||||||||||||||||||||||||||||
| 62 | (?: | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | (?: :: )+ ### arisdottle (allow one or many times) | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | $PKG_ADDL_WORD_REGEXP ### a package word | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | )* # ^ zero, one or many times | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | (?: | ||||||||||||||||||||||||||||||||||||||||||||
| 67 | :: # allow trailing arisdottle | ||||||||||||||||||||||||||||||||||||||||||||
| 68 | )? | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | my $PKG_REGEXP = qr{ # match a package declaration | |||||||||||||||||||||||||||||||||||||||||||
| 72 | ^[\s\{;]* # intro chars on a line | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | package # the word 'package' | ||||||||||||||||||||||||||||||||||||||||||||
| 74 | \s+ # whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 75 | ($PKG_NAME_REGEXP) # a package name | ||||||||||||||||||||||||||||||||||||||||||||
| 76 | \s* # optional whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | ($V_NUM_REGEXP)? # optional version number | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | \s* # optional whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | [;\{] # semicolon line terminator or block start (since 5.16) | ||||||||||||||||||||||||||||||||||||||||||||
| 80 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | my $CLASS_REGEXP = qr{ # match a class declaration (core since 5.38) | |||||||||||||||||||||||||||||||||||||||||||
| 83 | ^[\s\{;]* # intro chars on a line | ||||||||||||||||||||||||||||||||||||||||||||
| 84 | class # the word 'class' | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | \s+ # whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | ($PKG_NAME_REGEXP) # a package name | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | \s* # optional whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 88 | ($V_NUM_REGEXP)? # optional version number | ||||||||||||||||||||||||||||||||||||||||||||
| 89 | \s* # optional whitespace | ||||||||||||||||||||||||||||||||||||||||||||
| 90 | [:;\{] # attribute start, semicolon line terminator or block start | ||||||||||||||||||||||||||||||||||||||||||||
| 91 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | my $VARNAME_REGEXP = qr{ # match fully-qualified VERSION name | |||||||||||||||||||||||||||||||||||||||||||
| 94 | ([\$*]) # sigil - $ or * | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | ( | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | ( # optional leading package name | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | (?:::|\')? # possibly starting like just :: (a la $::VERSION) | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | (?:\w+(?:::|\'))* # Foo::Bar:: ... | ||||||||||||||||||||||||||||||||||||||||||||
| 99 | )? | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | VERSION | ||||||||||||||||||||||||||||||||||||||||||||
| 101 | )\b | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | my $VERS_REGEXP = qr{ # match a VERSION definition | |||||||||||||||||||||||||||||||||||||||||||
| 105 | (?: | ||||||||||||||||||||||||||||||||||||||||||||
| 106 | \(\s*$VARNAME_REGEXP\s*\) # with parens | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | | | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | $VARNAME_REGEXP # without parens | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | ) | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | \s* | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | =[^=~>] # = but not ==, nor =~, nor => | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | }x; | ||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 122 | ▶ | sub new_from_file { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_file: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 122 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 122 | my $filename = File::Spec->rel2abs( shift ); | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 122 | ▶ | return undef unless defined( $filename ) && -f $filename; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $filename and -f $filename
MC/DC50%1/2
defined $filename and -f $filename
defined $filename
-f $filename
Truth table66%2/3
A and B
A= defined $filenameB= -f $filename
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 121 | return $class->_init(undef, $filename, @_); | |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | sub new_from_handle { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_handle: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | ▶ | return undef unless defined($handle) && defined($filename); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $handle and defined $filename
MC/DC50%1/2
defined $handle and defined $filename
defined $handle
defined $filename
Truth table66%2/3
A and B
A= defined $handleB= defined $filename
| |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | $filename = File::Spec->rel2abs( $filename ); | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | return $class->_init(undef, $filename, @_, handle => $handle); | |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | sub new_from_module { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_module: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | my %props = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | ▶ | $props{inc} ||= \@INC; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$props{"inc"} ||= \@INC
MC/DC100%1/1
$props{"inc"} ||= \@INC
$props{"inc"}
Truth table100%2/2
A
A= $props{"inc"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 9 | my $filename = $class->find_module_by_name( $module, $props{inc} ); | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 9 | ▶ | return undef unless defined( $filename ) && -f $filename; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $filename and -f $filename
MC/DC50%1/2
defined $filename and -f $filename
defined $filename
-f $filename
Truth table66%2/3
A and B
A= defined $filenameB= -f $filename
| |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | return $class->_init($module, $filename, %props); | |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | my $compare_versions = sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my ($v1, $op, $v2) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | $v1 = version->new($v1) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 150 | unless UNIVERSAL::isa($v1,'version'); | ||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | my $eval_str = "\$v1 $op \$v2"; | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | my $result = eval $eval_str; | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | log_info { "error comparing versions: '$eval_str' $@" } if $@; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 10 | ▶ | my $normalize_version = sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 10 | my ($version) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 10 | ▶ | if ( $version =~ /[=<>!,]/ ) { # logic, not just version | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 162 | # take as is without modification | ||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif ( ref $version eq 'version' ) { # version objects | ||||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | ▶ | $version = $version->is_qv ? $version->normal : $version->stringify; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots | ||||||||||||||||||||||||||||||||||||||||||||
| 168 | # normalize string tuples without "v": "1.2.3" -> "v1.2.3" | ||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | $version = "v$version"; | |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 172 | # leave alone | ||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | return $version; | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | # separate out some of the conflict resolution logic | ||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | ▶ | my $resolve_module_versions = sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | my $packages = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | my( $file, $version ); | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | my $err = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | foreach my $p ( @$packages ) { | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | ▶ | if ( defined( $p->{version} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | ▶ | if ( defined( $version ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | if ( $compare_versions->( $version, '!=', $p->{version} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | $err .= " $p->{file} ($p->{version})\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 191 | # same version declared multiple times, ignore | ||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 195 | 6 | $file = $p->{file}; | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | $version = $p->{version}; | |||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | $file ||= $p->{file} if defined( $p->{file} ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file ||= $p->{"file"}
MC/DC0%0/2
$file ||= $p->{"file"}
$file
$p->{"file"}
Truth table33%1/3
A ||= B
A= $fileB= $p->{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | if ( $err ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | $err = " $file ($version)\n" . $err; | |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my %result = ( | |||||||||||||||||||||||||||||||||||||||||||
| 207 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||||
| 208 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||||
| 209 | err => $err | ||||||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | sub provides { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
provides: called CC=11 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | ▶ | croak "provides() requires key/value pairs \n" if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | croak "provides() takes only one of 'dir' or 'files'\n" | ||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | ▶ | if $args{dir} && $args{files}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"dir"} and $args{"files"}
MC/DC0%0/2
$args{"dir"} and $args{"files"}
$args{"dir"}
$args{"files"}
Truth table33%1/3
A and B
A= $args{"dir"}B= $args{"files"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | croak "provides() requires a 'version' argument" | ||||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | unless defined $args{version}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | croak "provides() does not support version '$args{version}' metadata" | ||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | unless grep $args{version} eq $_, qw/1.4 2/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | $args{prefix} = 'lib' unless defined $args{prefix}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | my $p; | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | if ( $args{dir} ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | $p = $class->package_versions_from_directory($args{dir}); | |||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 237 | croak "provides() requires 'files' to be an array reference\n" | ||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | ▶ | unless ref $args{files} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | $p = $class->package_versions_from_directory($args{files}); | |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Now, fix up files with prefix | ||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | if ( length $args{prefix} ) { # check in case disabled with q{} | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | $args{prefix} =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | for my $v ( values %$p ) { | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | $v->{file} = "$args{prefix}/$v->{file}"; | |||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | return $p | |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | ▶ | sub package_versions_from_directory { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_versions_from_directory: called CC=22 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | my ( $class, $dir, $files ) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 5 | my @files; | |||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | if ( $files ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | @files = @$files; | |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 262 | find( { | ||||||||||||||||||||||||||||||||||||||||||||
| 263 | 8 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | ▶ | push @files, $_ if -f $_ && /\.pm$/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $_ and /\.pm$/
MC/DC50%1/2
-f $_ and /\.pm$/
-f $_
/\.pm$/
Truth table66%2/3
A and B
A= -f $_B= /\.pm$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 265 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | no_chdir => 1, | |||||||||||||||||||||||||||||||||||||||||||
| 267 | }, $dir ); | ||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | # First, we enumerate all packages & versions, | ||||||||||||||||||||||||||||||||||||||||||||
| 271 | # separating into primary & alternative candidates | ||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | my( %prime, %alt ); | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 5 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | my $mapped_filename = File::Spec->abs2rel( $file, $dir ); | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | my @path = File::Spec->splitdir( $mapped_filename ); | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 5 | (my $prime_package = join( '::', @path )) =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | my $pm_info = $class->new_from_file( $file ); | |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | foreach my $package ( $pm_info->packages_inside ) { | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 21 | ▶ | next if $package eq 'main'; # main can appear numerous times, ignore | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 17 | ▶ | next if $package eq 'DB'; # special debugging package, ignore | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 13 | ▶ | next if grep /^_/, split( /::/, $package ); # private package, ignore | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 9 | my $version = $pm_info->version( $package ); | |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 9 | ▶ | $prime_package = $package if lc($prime_package) eq lc($package); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 9 | ▶ | if ( $package eq $prime_package ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | ▶ | if ( exists( $prime{$package} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | croak "Unexpected conflict in '$package'; multiple versions found.\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 293 | 5 | ▶ | $mapped_filename = "$package.pm" if lc("$package.pm") eq lc($mapped_filename); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 5 | $prime{$package}{file} = $mapped_filename; | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 5 | ▶ | $prime{$package}{version} = $version if defined( $version ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 298 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | push( @{$alt{$package}}, { | |||||||||||||||||||||||||||||||||||||||||||
| 300 | file => $mapped_filename, | ||||||||||||||||||||||||||||||||||||||||||||
| 301 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||||
| 302 | } ); | ||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Then we iterate over all the packages found above, identifying conflicts | ||||||||||||||||||||||||||||||||||||||||||||
| 308 | # and selecting the "best" candidate for recording the file & version | ||||||||||||||||||||||||||||||||||||||||||||
| 309 | # for each package. | ||||||||||||||||||||||||||||||||||||||||||||
| 310 | 5 | foreach my $package ( keys( %alt ) ) { | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 5 | my $result = $resolve_module_versions->( $alt{$package} ); | |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 5 | ▶ | if ( exists( $prime{$package} ) ) { # primary package selected | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | if ( $result->{err} ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 316 | # Use the selected primary package, but there are conflicting | ||||||||||||||||||||||||||||||||||||||||||||
| 317 | # errors among multiple alternative packages that need to be | ||||||||||||||||||||||||||||||||||||||||||||
| 318 | # reported | ||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | ▶ | log_info { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 320 | "Found conflicting versions for package '$package'\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 321 | " $prime{$package}{file} ($prime{$package}{version})\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 322 | $result->{err} | ||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif ( defined( $result->{version} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 327 | # There is a primary package selected, and exactly one | ||||||||||||||||||||||||||||||||||||||||||||
| 328 | # alternative package | ||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | if ( exists( $prime{$package}{version} ) && | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $prime{$package}{"version"} and defined $prime{$package}{"version"}
MC/DC0%0/2
exists $prime{$package}{"version"} and defined $prime{$package}{"version"}
exists $prime{$package}{"version"}
defined $prime{$package}{"version"}
Truth table0%0/3
A and B
A= exists $prime{$package}{"version"}B= defined $prime{$package}{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 331 | defined( $prime{$package}{version} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Unless the version of the primary package agrees with the | ||||||||||||||||||||||||||||||||||||||||||||
| 333 | # version of the alternative package, report a conflict | ||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | if ( $compare_versions->( | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 335 | $prime{$package}{version}, '!=', $result->{version} | ||||||||||||||||||||||||||||||||||||||||||||
| 336 | ) | ||||||||||||||||||||||||||||||||||||||||||||
| 337 | ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | ▶ | log_info { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | "Found conflicting versions for package '$package'\n" . | |||||||||||||||||||||||||||||||||||||||||||
| 341 | " $prime{$package}{file} ($prime{$package}{version})\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 342 | " $result->{file} ($result->{version})\n" | ||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 348 | # The prime package selected has no version so, we choose to | ||||||||||||||||||||||||||||||||||||||||||||
| 349 | # use any alternative package that does have a version | ||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | $prime{$package}{file} = $result->{file}; | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | $prime{$package}{version} = $result->{version}; | |||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 356 | # no alt package found with a version, but we have a prime | ||||||||||||||||||||||||||||||||||||||||||||
| 357 | # package so we use it whether it has a version or not | ||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 361 | else { # No primary package was selected, use the best alternative | ||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | 5 | ▶ | if ( $result->{err} ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 364 | 2 | ▶ | log_info { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 365 | "Found conflicting versions for package '$package'\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 366 | $result->{err} | ||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Despite possible conflicting versions, we choose to record | ||||||||||||||||||||||||||||||||||||||||||||
| 371 | # something rather than nothing | ||||||||||||||||||||||||||||||||||||||||||||
| 372 | 5 | $prime{$package}{file} = $result->{file}; | |||||||||||||||||||||||||||||||||||||||||||
| 373 | $prime{$package}{version} = $result->{version} | ||||||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | ▶ | if defined( $result->{version} ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | # Normalize versions. Can't use exists() here because of bug in YAML::Node. | ||||||||||||||||||||||||||||||||||||||||||||
| 379 | # XXX "bug in YAML::Node" comment seems irrelevant -- dagolden, 2009-05-18 | ||||||||||||||||||||||||||||||||||||||||||||
| 380 | 5 | for (grep defined $_->{version}, values %prime) { | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 9 | $_->{version} = $normalize_version->( $_->{version} ); | |||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 5 | return \%prime; | |||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 8 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 130 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 130 | my $module = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 130 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 130 | my %props = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 130 | my $handle = delete $props{handle}; | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 130 | my( %valid_props, @valid_props ); | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 130 | @valid_props = qw( collect_pod inc decode_pod ); | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 130 | @valid_props{@valid_props} = delete( @props{@valid_props} ); | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 130 | ▶ | warn "Unknown properties: @{[keys %props]}\n" if scalar( %props ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 130 | my %data = ( | |||||||||||||||||||||||||||||||||||||||||||
| 402 | module => $module, | ||||||||||||||||||||||||||||||||||||||||||||
| 403 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||||
| 404 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||||
| 405 | packages => [], | ||||||||||||||||||||||||||||||||||||||||||||
| 406 | versions => {}, | ||||||||||||||||||||||||||||||||||||||||||||
| 407 | pod => {}, | ||||||||||||||||||||||||||||||||||||||||||||
| 408 | pod_headings => [], | ||||||||||||||||||||||||||||||||||||||||||||
| 409 | collect_pod => 0, | ||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | %valid_props, | ||||||||||||||||||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | 130 | my $self = bless(\%data, $class); | |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 130 | ▶ | if ( not $handle ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 126 | my $filename = $self->{filename}; | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 126 | ▶ | open $handle, '<', $filename | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 419 | or croak( "Can't open '$filename': $!" ); | ||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | 126 | $self->_handle_bom($handle, $filename); | |||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 423 | 130 | $self->_parse_fh($handle); | |||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 130 | @{$self->{packages}} = __uniq(@{$self->{packages}}); | |||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | 129 | ▶ | unless($self->{module} and length($self->{module})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"module"} and length $self->{"module"}
MC/DC50%1/2
$self->{"module"} and length $self->{"module"}
$self->{"module"}
length $self->{"module"}
Truth table66%2/3
A and B
A= $self->{"module"}B= length $self->{"module"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 428 | # CAVEAT (possible TODO): .pmc files not treated the same as .pm | ||||||||||||||||||||||||||||||||||||||||||||
| 429 | 123 | ▶ | if ($self->{filename} =~ /\.pm$/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 430 | 114 | my ($v, $d, $f) = File::Spec->splitpath($self->{filename}); | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 114 | $f =~ s/\..+$//; | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 114 | my @candidates = grep /(^|::)$f$/, @{$self->{packages}}; | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 114 | $self->{module} = shift(@candidates); # this may be undef | |||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 435 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 436 | # this seems like an atrocious heuristic, albeit marginally better than | ||||||||||||||||||||||||||||||||||||||||||||
| 437 | # what was here before. It should be rewritten entirely to be more like | ||||||||||||||||||||||||||||||||||||||||||||
| 438 | # "if it's not a .pm file, it's not require()able as a name, therefore | ||||||||||||||||||||||||||||||||||||||||||||
| 439 | # name() should be undef." | ||||||||||||||||||||||||||||||||||||||||||||
| 440 | 9 | ▶ | if ((grep /main/, @{$self->{packages}}) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
grep /main/, @{$$self{"packages"};} or grep /main/, keys %{$$self{"versions"};}
MC/DC100%2/2
grep /main/, @{$$self{"packages"};} or grep /main/, keys %{$$self{"versions"};}
grep /main/, @{$$self{"packages"};}
grep /main/, keys %{$$self{"versions"};}
Truth table100%3/3
A or B
A= grep /main/, @{$$self{"packages"};}B= grep /main/, keys %{$$self{"versions"};}
| |||||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | or (grep /main/, keys %{$self->{versions}})) { | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | $self->{module} = 'main'; | |||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 444 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 445 | # TODO: this should maybe default to undef instead | ||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | $self->{module} = $self->{packages}[0] || ''; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'packages'}[0] || ''
MC/DC0%0/1
$self->{'packages'}[0] || ''
$self->{'packages'}[0]
Truth table50%1/2
A
A= $self->{'packages'}[0]
| |||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | $self->{version} = $self->{versions}{$self->{module}} | ||||||||||||||||||||||||||||||||||||||||||||
| 452 | 129 | ▶ | if defined( $self->{module} ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | 129 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | # class method | ||||||||||||||||||||||||||||||||||||||||||||
| 458 | 10 | ▶ | sub _do_find_module { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_find_module: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 8 | ▶ | my $module = shift || croak 'find_module_by_name() requires a package name'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || croak('find_module_by_name() requires a package name')
MC/DC0%0/1
shift() || croak('find_module_by_name() requires a package name')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 8 | ▶ | my $dirs = shift || \@INC; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || \@INC
MC/DC100%1/1
shift() || \@INC
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 8 | my $file = File::Spec->catfile(split( /::/, $module)); | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 8 | foreach my $dir ( @$dirs ) { | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 10 | my $testfile = File::Spec->catfile($dir, $file); | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 10 | ▶ | return [ File::Spec->rel2abs( $testfile ), $dir ] | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $testfile and not -d _
MC/DC0%0/2
-e $testfile and not -d _
-e $testfile
not -d _
Truth table33%1/3
A and not(B)
A= -e $testfileB= not -d _
| |||||||||||||||||||||||||||||||||||||||||||||
| 467 | if -e $testfile and !-d _; # For stuff like ExtUtils::xsubpp | ||||||||||||||||||||||||||||||||||||||||||||
| 468 | # CAVEAT (possible TODO): .pmc files are not discoverable here | ||||||||||||||||||||||||||||||||||||||||||||
| 469 | 10 | $testfile .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 10 | ▶ | return [ File::Spec->rel2abs( $testfile ), $dir ] | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 471 | if -e $testfile; | ||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | # class method | ||||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | ▶ | sub find_module_by_name { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_module_by_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 478 | 8 | ▶ | my $found = shift()->_do_find_module(@_) or return; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 479 | 7 | return $found->[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | # class method | ||||||||||||||||||||||||||||||||||||||||||||
| 483 | 2 | ▶ | sub find_module_dir_by_name { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_module_dir_by_name: called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | my $found = shift()->_do_find_module(@_) or return; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return $found->[1]; | |||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | # given a line of perl code, attempt to parse it if it looks like a | ||||||||||||||||||||||||||||||||||||||||||||
| 490 | # $VERSION assignment, returning sigil, full name, & package name | ||||||||||||||||||||||||||||||||||||||||||||
| 491 | 141 | ▶ | sub _parse_version_expression { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_version_expression: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||
| 492 | 139 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 139 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 139 | my( $sigil, $variable_name, $package); | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 139 | ▶ | if ( $line =~ /$VERS_REGEXP/o ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 497 | 118 | ▶ | ( $sigil, $variable_name, $package) = $2 ? ( $1, $2, $3 ) : ( $4, $5, $6 ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 498 | 118 | ▶ | if ( $package ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 499 | 20 | ▶ | $package = ($package eq '::') ? 'main' : $package; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 20 | $package =~ s/::$//; | |||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 139 | return ( $sigil, $variable_name, $package ); | |||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | # Look for a UTF-8/UTF-16BE/UTF-16LE BOM at the beginning of the stream. | ||||||||||||||||||||||||||||||||||||||||||||
| 508 | # If there's one, then skip it and set the :encoding layer appropriately. | ||||||||||||||||||||||||||||||||||||||||||||
| 509 | 126 | ▶ | sub _handle_bom { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_bom: called CC=13 SCAR=27.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 510 | 125 | my ($self, $fh, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 125 | my $pos = tell $fh; | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 125 | ▶ | return unless defined $pos; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | 125 | my $buf = ' ' x 2; | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 125 | my $count = read $fh, $buf, length $buf; | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 125 | ▶ | return unless defined $count and $count >= 2; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $count and $count >= 2
MC/DC0%0/2
defined $count and $count >= 2
defined $count
$count >= 2
Truth table33%1/3
A and B
A= defined $countB= $count >= 2
| |||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||
| 519 | 125 | my $encoding; | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 125 | ▶ | if ( $buf eq "\x{FE}\x{FF}" ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | $encoding = 'UTF-16BE'; | |||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 523 | elsif ( $buf eq "\x{FF}\x{FE}" ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | $encoding = 'UTF-16LE'; | |||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 526 | elsif ( $buf eq "\x{EF}\x{BB}" ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | $buf = ' '; | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | $count = read $fh, $buf, length $buf; | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | ▶ | if ( defined $count and $count >= 1 and $buf eq "\x{BF}" ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $count and $count >= 1 and $buf eq "\277"
defined $count and $count >= 1
MC/DC0%0/3
defined $count and $count >= 1 and $buf eq "\277"
defined $count
$count >= 1
$buf eq "\277"
Truth table25%1/4
A and B and C
A= defined $countB= $count >= 1C= $buf eq "\277"
| |||||||||||||||||||||||||||||||||||||||||||||
| 530 | 1 | $encoding = 'UTF-8'; | |||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | 125 | ▶ | if ( defined $encoding ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 535 | 3 | ▶ | if ( "$]" >= 5.008 ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 536 | 3 | binmode( $fh, ":encoding($encoding)" ); | |||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 539 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 540 | 122 | ▶ | seek $fh, $pos, SEEK_SET | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 541 | or croak( sprintf "Can't reset position to the top of '$filename'" ); | ||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 125 | return $encoding; | |||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | 130 | ▶ | sub _parse_fh { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_fh: called CC=45 SCAR=38.1
| |||||||||||||||||||||||||||||||||||||||||||||
| 548 | 129 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | 129 | my( $in_pod, $seen_end, $need_vers ) = ( 0, 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 129 | my( @packages, %vers, %pod, @pod ); | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 129 | my $package = 'main'; | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 129 | my $pod_sect = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 129 | my $pod_data = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 129 | my $in_end = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 129 | my $encoding = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||
| 558 | 129 | ▶ | while (defined( my $line = <$fh> )) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1753 | my $line_num = $.; | |||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1753 | chomp( $line ); | |||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | # From toke.c : any line that begins by "=X", where X is an alphabetic | ||||||||||||||||||||||||||||||||||||||||||||
| 564 | # character, introduces a POD segment. | ||||||||||||||||||||||||||||||||||||||||||||
| 565 | 1753 | my $is_cut; | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 1753 | ▶ | if ( $line =~ /^=([a-zA-Z].*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 567 | 99 | my $cmd = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 568 | # Then it goes back to Perl code for "=cutX" where X is a non-alphabetic | ||||||||||||||||||||||||||||||||||||||||||||
| 569 | # character (which includes the newline, but here we chomped it away). | ||||||||||||||||||||||||||||||||||||||||||||
| 570 | 99 | $is_cut = $cmd =~ /^cut(?:[^a-zA-Z]|$)/; | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 99 | $in_pod = !$is_cut; | |||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1753 | ▶ | if ( $in_pod ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | 469 | ▶ | if ( $line =~ /^=head[1-4]\s+(.+)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 577 | 45 | push( @pod, $1 ); | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 45 | ▶ | if ( $self->{collect_pod} && length( $pod_data ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"collect_pod"} and length $pod_data
MC/DC100%2/2
$self->{"collect_pod"} and length $pod_data
$self->{"collect_pod"}
length $pod_data
Truth table100%3/3
A and B
A= $self->{"collect_pod"}B= length $pod_data
| |||||||||||||||||||||||||||||||||||||||||||||
| 579 | 4 | $pod{$pod_sect} = $pod_data; | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 4 | $pod_data = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 582 | 45 | $pod_sect = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 584 | elsif ( $self->{collect_pod} ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 585 | 25 | ▶ | if ( $self->{decode_pod} && $line =~ /^=encoding ([\w-]+)/ ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"decode_pod"} and $line =~ /^=encoding ([\w-]+)/
MC/DC100%2/2
$self->{"decode_pod"} and $line =~ /^=encoding ([\w-]+)/
$self->{"decode_pod"}
$line =~ /^=encoding ([\w-]+)/
Truth table100%3/3
A and B
A= $self->{"decode_pod"}B= $line =~ /^=encoding ([\w-]+)/
| |||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | $encoding = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 588 | 25 | $pod_data .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 590 | 469 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 592 | elsif ( $is_cut ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 593 | 10 | ▶ | if ( $self->{collect_pod} && length( $pod_data ) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"collect_pod"} and length $pod_data
MC/DC50%1/2
$self->{"collect_pod"} and length $pod_data
$self->{"collect_pod"}
length $pod_data
Truth table66%2/3
A and B
A= $self->{"collect_pod"}B= length $pod_data
| |||||||||||||||||||||||||||||||||||||||||||||
| 594 | 2 | $pod{$pod_sect} = $pod_data; | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 2 | $pod_data = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 597 | 10 | $pod_sect = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | # Skip after __END__ | ||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1274 | ▶ | next if $in_end; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | # Skip comments in code | ||||||||||||||||||||||||||||||||||||||||||||
| 605 | 1272 | ▶ | next if $line =~ /^\s*#/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | # Would be nice if we could also check $in_string or something too | ||||||||||||||||||||||||||||||||||||||||||||
| 608 | 1174 | ▶ | if ($line eq '__END__') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | $in_end++; | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | 1172 | ▶ | last if $line eq '__DATA__'; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | # parse $line to see if it's a $VERSION declaration | ||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1171 | ▶ | my( $version_sigil, $version_fullname, $version_package ) = | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 617 | index($line, 'VERSION') >= 1 | ||||||||||||||||||||||||||||||||||||||||||||
| 618 | ? $self->_parse_version_expression( $line ) | ||||||||||||||||||||||||||||||||||||||||||||
| 619 | : (); | ||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1171 | ▶ | if ( $line =~ /$PKG_REGEXP/o or $line =~ /$CLASS_REGEXP/ ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
$line =~ /$PKG_REGEXP/o or $line =~ /$CLASS_REGEXP/x
MC/DC100%2/2
$line =~ /$PKG_REGEXP/o or $line =~ /$CLASS_REGEXP/x
$line =~ /$PKG_REGEXP/o
$line =~ /$CLASS_REGEXP/x
Truth table100%3/3
A or B
A= $line =~ /$PKG_REGEXP/oB= $line =~ /$CLASS_REGEXP/x
| |||||||||||||||||||||||||||||||||||||||||||||
| 622 | 156 | $package = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 156 | my $version = $2; | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 156 | ▶ | push( @packages, $package ) unless grep( $package eq $_, @packages ); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 625 | 156 | ▶ | $need_vers = defined $version ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | 156 | ▶ | if ( not exists $vers{$package} and defined $version ){ | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $vers{$package} and defined $version
MC/DC100%2/2
not exists $vers{$package} and defined $version
not exists $vers{$package}
defined $version
Truth table100%3/3
not(A) and B
A= not exists $vers{$package}B= defined $version
| |||||||||||||||||||||||||||||||||||||||||||||
| 628 | # Upgrade to a version object. | ||||||||||||||||||||||||||||||||||||||||||||
| 629 | 19 | my $dwim_version = eval { _dwim_version($version) }; | |||||||||||||||||||||||||||||||||||||||||||
| 630 | 19 | ▶ | croak "Version '$version' from $self->{filename} does not appear to be valid:\n$line\n\nThe fatal error was: $@\n" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 631 | unless defined $dwim_version; # "0" is OK! | ||||||||||||||||||||||||||||||||||||||||||||
| 632 | 19 | $vers{$package} = $dwim_version; | |||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||
| 636 | # VERSION defined with full package spec, i.e. $Module::VERSION | ||||||||||||||||||||||||||||||||||||||||||||
| 637 | ▶ | elsif ( $version_fullname && $version_package ) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$version_fullname and $version_package
MC/DC100%2/2
$version_fullname and $version_package
$version_fullname
$version_package
Truth table100%3/3
A and B
A= $version_fullnameB= $version_package
| |||||||||||||||||||||||||||||||||||||||||||||
| 638 | # we do NOT save this package in found @packages | ||||||||||||||||||||||||||||||||||||||||||||
| 639 | 20 | ▶ | $need_vers = 0 if $version_package eq $package; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 20 | ▶ | unless ( defined $vers{$version_package} && length $vers{$version_package} ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $vers{$version_package} and length $vers{$version_package}
MC/DC50%1/2
defined $vers{$version_package} and length $vers{$version_package}
defined $vers{$version_package}
length $vers{$version_package}
Truth table66%2/3
A and B
A= defined $vers{$version_package}B= length $vers{$version_package}
| |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 18 | $vers{$version_package} = $self->_evaluate_version_line( $version_sigil, $version_fullname, $line ); | |||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | # first non-comment line in undeclared package main is VERSION | ||||||||||||||||||||||||||||||||||||||||||||
| 647 | ▶ | elsif ( $package eq 'main' && $version_fullname && !exists($vers{main}) ) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$package eq "main" and $version_fullname and not exists $vers{"main"}
$package eq "main" and $version_fullname
MC/DC100%3/3
$package eq "main" and $version_fullname and not exists $vers{"main"}
$package eq "main"
$version_fullname
not exists $vers{"main"}
Truth table100%4/4
A and B and not(C)
A= $package eq "main"B= $version_fullnameC= not exists $vers{"main"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | $need_vers = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 8 | my $v = $self->_evaluate_version_line( $version_sigil, $version_fullname, $line ); | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 8 | $vers{$package} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 8 | push( @packages, 'main' ); | |||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | # first non-comment line in undeclared package defines package main | ||||||||||||||||||||||||||||||||||||||||||||
| 655 | ▶ | elsif ( $package eq 'main' && !exists($vers{main}) && $line =~ /\w/ ) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$package eq "main" and not exists $vers{"main"} and $line =~ /\w/
$package eq "main" and not exists $vers{"main"}
MC/DC100%3/3
$package eq "main" and not exists $vers{"main"} and $line =~ /\w/
$package eq "main"
not exists $vers{"main"}
$line =~ /\w/
Truth table100%4/4
A and not(B) and C
A= $package eq "main"B= not exists $vers{"main"}C= $line =~ /\w/
| |||||||||||||||||||||||||||||||||||||||||||||
| 656 | 9 | $need_vers = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 9 | $vers{main} = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 9 | push( @packages, 'main' ); | |||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | # only keep if this is the first $VERSION seen | ||||||||||||||||||||||||||||||||||||||||||||
| 662 | ▶ | elsif ( $version_fullname && $need_vers ) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$version_fullname and $need_vers
MC/DC100%2/2
$version_fullname and $need_vers
$version_fullname
$need_vers
Truth table100%3/3
A and B
A= $version_fullnameB= $need_vers
| |||||||||||||||||||||||||||||||||||||||||||||
| 663 | 87 | $need_vers = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 87 | my $v = $self->_evaluate_version_line( $version_sigil, $version_fullname, $line ); | |||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 87 | ▶ | unless ( defined $vers{$package} && length $vers{$package} ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $vers{$package} and length $vers{$package}
MC/DC0%0/2
defined $vers{$package} and length $vers{$package}
defined $vers{$package}
length $vers{$package}
Truth table66%2/3
A and B
A= defined $vers{$package}B= length $vers{$package}
| |||||||||||||||||||||||||||||||||||||||||||||
| 667 | 87 | $vers{$package} = $v; | |||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 670 | } # end loop over each line | ||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | 129 | ▶ | if ( $self->{collect_pod} && length($pod_data) ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"collect_pod"} and length $pod_data
MC/DC100%2/2
$self->{"collect_pod"} and length $pod_data
$self->{"collect_pod"}
length $pod_data
Truth table100%3/3
A and B
A= $self->{"collect_pod"}B= length $pod_data
| |||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | $pod{$pod_sect} = $pod_data; | |||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | 129 | ▶ | if ( $self->{decode_pod} && $encoding ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"decode_pod"} and $encoding
MC/DC50%1/2
$self->{"decode_pod"} and $encoding
$self->{"decode_pod"}
$encoding
Truth table66%2/3
A and B
A= $self->{"decode_pod"}B= $encoding
| |||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||
| 678 | 1 | $_ = Encode::decode( $encoding, $_ ) for values %pod; | |||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||
| 681 | 129 | $self->{versions} = \%vers; | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 129 | $self->{packages} = \@packages; | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 129 | $self->{pod} = \%pod; | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 129 | $self->{pod_headings} = \@pod; | |||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | sub __uniq (@) | ||||||||||||||||||||||||||||||||||||||||||||
| 688 | 130 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__uniq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 689 | 129 | my (%seen, $key); | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 129 | grep !$seen{ $key = $_ }++, @_; | |||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||
| 693 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 694 | 8 | my $pn = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 114 | ▶ | sub _evaluate_version_line { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evaluate_version_line: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||
| 696 | 113 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 113 | my( $sigil, $variable_name, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||
| 699 | # We compile into a local sub because 'use version' would cause | ||||||||||||||||||||||||||||||||||||||||||||
| 700 | # compiletime/runtime issues with local() | ||||||||||||||||||||||||||||||||||||||||||||
| 701 | 113 | $pn++; # everybody gets their own package | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 113 | my $eval = qq{ my \$dummy = q# Hide from _packages_inside() | |||||||||||||||||||||||||||||||||||||||||||
| 703 | #; package Module::Metadata::_version::p${pn}; | ||||||||||||||||||||||||||||||||||||||||||||
| 704 | use version; | ||||||||||||||||||||||||||||||||||||||||||||
| 705 | sub { | ||||||||||||||||||||||||||||||||||||||||||||
| 706 | local $sigil$variable_name; | ||||||||||||||||||||||||||||||||||||||||||||
| 707 | $line; | ||||||||||||||||||||||||||||||||||||||||||||
| 708 | return \$$variable_name if defined \$$variable_name; | ||||||||||||||||||||||||||||||||||||||||||||
| 709 | return \$Module::Metadata::_version::p${pn}::$variable_name; | ||||||||||||||||||||||||||||||||||||||||||||
| 710 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 711 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 113 | ▶ | $eval = $1 if $eval =~ m{^(.+)}s; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||
| 715 | 113 | local $^W; | |||||||||||||||||||||||||||||||||||||||||||
| 716 | # Try to get the $VERSION | ||||||||||||||||||||||||||||||||||||||||||||
| 717 | 113 | my $vsub = __clean_eval($eval); | |||||||||||||||||||||||||||||||||||||||||||
| 718 | # some modules say $VERSION <equal sign> $Foo::Bar::VERSION, but Foo::Bar isn't | ||||||||||||||||||||||||||||||||||||||||||||
| 719 | # installed, so we need to hunt in ./lib for it | ||||||||||||||||||||||||||||||||||||||||||||
| 720 | 113 | ▶ | if ( $@ =~ /Can't locate/ && -d 'lib' ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ =~ /Can't locate/ and -d "lib"
MC/DC0%0/2
$@ =~ /Can't locate/ and -d "lib"
$@ =~ /Can't locate/
-d "lib"
Truth table33%1/3
A and B
A= $@ =~ /Can't locate/B= -d "lib"
| |||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | local @INC = ('lib',@INC); | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $vsub = __clean_eval($eval); | |||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 724 | 113 | ▶ | warn "Error evaling version line '$eval' in $self->{filename}: $@\n" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 725 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||
| 727 | 113 | ▶ | (ref($vsub) eq 'CODE') or | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 728 | croak "failed to build version sub for $self->{filename}"; | ||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | 113 | my $result = eval { $vsub->() }; | |||||||||||||||||||||||||||||||||||||||||||
| 731 | # FIXME: $eval is not the right thing to print here | ||||||||||||||||||||||||||||||||||||||||||||
| 732 | 113 | ▶ | croak "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error was: $@\n" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 733 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | # Upgrade it into a version object | ||||||||||||||||||||||||||||||||||||||||||||
| 736 | 113 | my $version = eval { _dwim_version($result) }; | |||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||
| 738 | # FIXME: $eval is not the right thing to print here | ||||||||||||||||||||||||||||||||||||||||||||
| 739 | 113 | ▶ | croak "Version '$result' from $self->{filename} does not appear to be valid:\n$eval\n\nThe fatal error was: $@\n" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 740 | unless defined $version; # "0" is OK! | ||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 113 | return $version; | |||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||
| 746 | # Try to DWIM when things fail the lax version test in obvious ways | ||||||||||||||||||||||||||||||||||||||||||||
| 747 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 748 | 8 | my @version_prep = ( | |||||||||||||||||||||||||||||||||||||||||||
| 749 | # Best case, it just works | ||||||||||||||||||||||||||||||||||||||||||||
| 750 | 127 | ▶ | sub { return shift }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||
| 752 | # If we still don't have a version, try stripping any | ||||||||||||||||||||||||||||||||||||||||||||
| 753 | # trailing junk that is prohibited by lax rules | ||||||||||||||||||||||||||||||||||||||||||||
| 754 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 755 | 6 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 756 | 6 | $v =~ s{([0-9])[a-z-].*$}{$1}i; # 1.23-alpha or 1.23b | |||||||||||||||||||||||||||||||||||||||||||
| 757 | 6 | return $v; | |||||||||||||||||||||||||||||||||||||||||||
| 758 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||
| 760 | # Activestate apparently creates custom versions like '1.23_45_01', which | ||||||||||||||||||||||||||||||||||||||||||||
| 761 | # cause version.pm to think it's an invalid alpha. So check for that | ||||||||||||||||||||||||||||||||||||||||||||
| 762 | # and strip them | ||||||||||||||||||||||||||||||||||||||||||||
| 763 | 5 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 764 | 4 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 4 | my $num_dots = () = $v =~ m{(\.)}g; | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 4 | my $num_unders = () = $v =~ m{(_)}g; | |||||||||||||||||||||||||||||||||||||||||||
| 767 | 4 | my $leading_v = substr($v,0,1) eq 'v'; | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 4 | ▶ | if ( ! $leading_v && $num_dots < 2 && $num_unders > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $leading_v and $num_dots < 2 and $num_unders > 1
not $leading_v and $num_dots < 2
MC/DC66%2/3
not $leading_v and $num_dots < 2 and $num_unders > 1
not $leading_v
$num_dots < 2
$num_unders > 1
Truth table75%3/4
not(A) and B and C
A= not $leading_vB= $num_dots < 2C= $num_unders > 1
| |||||||||||||||||||||||||||||||||||||||||||||
| 769 | 2 | $v =~ s{_}{}g; | |||||||||||||||||||||||||||||||||||||||||||
| 770 | 2 | $num_unders = () = $v =~ m{(_)}g; | |||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 772 | 4 | return $v; | |||||||||||||||||||||||||||||||||||||||||||
| 773 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||
| 775 | # Worst case, try numifying it like we would have before version objects | ||||||||||||||||||||||||||||||||||||||||||||
| 776 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 777 | 2 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 10 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | return 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||
| 780 | }, | ||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||
| 782 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | 133 | ▶ | sub _dwim_version { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dwim_version: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 785 | 132 | my ($result) = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||
| 787 | 132 | ▶ | return $result if ref($result) eq 'version'; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||
| 789 | 127 | my ($version, $error); | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 127 | for my $f (@version_prep) { | |||||||||||||||||||||||||||||||||||||||||||
| 791 | 139 | $result = $f->($result); | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 139 | $version = eval { version->new($result) }; | |||||||||||||||||||||||||||||||||||||||||||
| 793 | 139 | ▶ | $error ||= $@ if $@; # capture first failure | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$error ||= $@
MC/DC0%0/2
$error ||= $@
$error
$@
Truth table66%2/3
A ||= B
A= $errorB= $@
| |||||||||||||||||||||||||||||||||||||||||||||
| 794 | 139 | ▶ | last if defined $version; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||
| 797 | 127 | ▶ | croak $error unless defined $version; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||
| 799 | 127 | return $version; | |||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||
| 803 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||
| 805 | # accessors | ||||||||||||||||||||||||||||||||||||||||||||
| 806 | 21 | ▶ | sub name { $_[0]->{module} } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1 | ▶ | sub filename { $_[0]->{filename} } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 809 | 34 | ▶ | sub packages_inside { @{$_[0]->{packages}} } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packages_inside: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 810 | 2 | ▶ | sub pod_inside { @{$_[0]->{pod_headings}} } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pod_inside: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 811 | 4 | ▶ | sub contains_pod { 0+@{$_[0]->{pod_headings}} } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains_pod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||
| 813 | 117 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 814 | 116 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 815 | 116 | ▶ | my $mod = shift || $self->{module}; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
shift() || $self->{'module'}
MC/DC100%2/2
shift() || $self->{'module'}
shift()
$self->{'module'}
Truth table100%3/3
A || B
A= shift()B= $self->{'module'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 816 | 116 | my $vers; | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 116 | ▶ | if ( defined( $mod ) && length( $mod ) && | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $mod and length $mod and exists $self->{"versions"}{$mod}
defined $mod and length $mod
MC/DC66%2/3
defined $mod and length $mod and exists $self->{"versions"}{$mod}
defined $mod
length $mod
exists $self->{"versions"}{$mod}
Truth table75%3/4
A and B and C
A= defined $modB= length $modC= exists $self->{"versions"}{$mod}
| |||||||||||||||||||||||||||||||||||||||||||||
| 818 | exists( $self->{versions}{$mod} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 819 | 99 | return $self->{versions}{$mod}; | |||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 821 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 822 | 17 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||
| 826 | 6 | ▶ | sub pod { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pod: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 827 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 5 | my $sect = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 5 | ▶ | if ( defined( $sect ) && length( $sect ) && | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $sect and length $sect and exists $self->{"pod"}{$sect}
defined $sect and length $sect
MC/DC33%1/3
defined $sect and length $sect and exists $self->{"pod"}{$sect}
defined $sect
length $sect
exists $self->{"pod"}{$sect}
Truth table50%2/4
A and B and C
A= defined $sectB= length $sectC= exists $self->{"pod"}{$sect}
| |||||||||||||||||||||||||||||||||||||||||||||
| 830 | exists( $self->{pod}{$sect} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 831 | 3 | return $self->{pod}{$sect}; | |||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 833 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 834 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||
| 838 | 9 | ▶ | sub is_indexable { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_indexable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 839 | 8 | my ($self, $package) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||||
| 841 | 8 | my @indexable_packages = grep $_ ne 'main', $self->packages_inside; | |||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||
| 843 | # check for specific package, if provided | ||||||||||||||||||||||||||||||||||||||||||||
| 844 | 8 | ▶ | return !! grep $_ eq $package, @indexable_packages if $package; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | # otherwise, check for any indexable packages at all | ||||||||||||||||||||||||||||||||||||||||||||
| 847 | 2 | return !! @indexable_packages; | |||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||
| 850 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||
| 852 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||