lib/CPAN/Maker/Utils.pm

filter: Statementstmt 56.9% 33 / 58 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 58.8% 10 / 17 Podpod 33.3% 2 / 6 totaltotal 43.6% 45 / 103 CC 8 SCAR 28.7
CC
8
Cov
44%
is_core
56.0
_is_obj
6.0
get_json_file
2.0
CRAP 17.7
« lib/CPAN/Maker/Role/ModuleUtils.pm ↑ Summary script/make-cpan-dist.pl »
1 package CPAN::Maker::Utils;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use CPAN::Maker::Constants qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use CLI::Simple::Utils qw(slurp_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $VERSION = '2.0.12';
15  
16 1 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our @EXPORT = qw(is_core trim is_array is_hash is_scalar get_json_file);
19  
20 ########################################################################
21 0 ▶sub is_core {
Subroutine is_core: not called CC=7 SCAR=40.3
Pod documented
22 ########################################################################
23 0 my ( $module_w_version, $perl_version ) = @_;
24  
25 0 my ( $module, $version ) = split /\s/xsm, $module_w_version;
26  
27 0 ▶ if ($perl_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version) 0 0 0
28 0 $perl_version = version->parse($perl_version);
29 }
30  
31 0 my @ms = Module::CoreList->find_modules( qr/\A$module\z/xsm, $perl_version );
32  
33 0 ▶ return $FALSE
Branch: 1 branch
BranchTrueFalseTotal
unless @ms 0 0 0
34 if !@ms;
35  
36 # is core and we don't care about version
37 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if @ms and not $perl_version && $version 0 0 0
Condition0%0/6
@ms and not $perl_version && $version
!ll&&!rl&&r
000
$perl_version && $version
!ll&&!rl&&r
000
MC/DC0%0/3
@ms and not $perl_version && $version
@ms $perl_version $version
Truth table0%0/4
A and not(B && C)
A= @msB= $perl_versionC= $version
ABCresult
0XX0
1110
10X1
1101
38 if @ms && ( !$perl_version || !$version );
39  
40 0 my $modules = Module::CoreList->find_version($perl_version);
41  
42 # return false if the version we want is > then provided by CORE
43 0 ▶ if ( version->parse($version) > version->parse( $modules->{$module} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse($version) > "version"->parse($modules->{$module})) 0 0 0
44 0 return $FALSE;
45 }
46  
47 0 return $TRUE;
48 }
49  
50 ########################################################################
51 0 ▶sub get_json_file {
Subroutine get_json_file: not called CC=1 SCAR=6.9
Pod undocumented
52 ########################################################################
53 0 my ($file) = @_;
54  
55 0 return slurp_json($file);
56 }
57  
58 ########################################################################
59 0 ▶sub _is_obj {
Subroutine _is_obj: not called CC=2 SCAR=17.9
60 ########################################################################
61 0 my ( $this, $type ) = @_;
62  
63 0 ▶ return ref $this && reftype($this) eq $type;
Condition0%0/3
ref $this && builtin::reftype($this) eq $type
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this && builtin::reftype($this) eq $type
ref $this builtin::reftype($this) eq $type
Truth table0%0/3
A && B
A= ref $thisB= builtin::reftype($this) eq $type
ABresult
0X0
100
111
64 }
65  
66 ########################################################################
67 0 ▶sub is_array {
Subroutine is_array: not called CC=1 SCAR=6.9
Pod undocumented
68 ########################################################################
69 0 my ($this) = @_;
70  
71 0 return _is_obj( $this, 'ARRAY' );
72 }
73  
74 ########################################################################
75 0 ▶sub is_scalar {
Subroutine is_scalar: not called CC=1 SCAR=6.9
Pod undocumented
76 ########################################################################
77 0 my ($this) = @_;
78  
79 0 return !ref $this;
80 }
81  
82 ########################################################################
83 0 ▶sub is_hash {
Subroutine is_hash: not called CC=1 SCAR=6.9
Pod undocumented
84 ########################################################################
85 0 my ($this) = @_;
86  
87 0 return _is_obj( $this, 'HASH' );
88 }
89  
90 ########################################################################
91 0 ▶sub trim {
Subroutine trim: not called CC=1 SCAR=6.9
Pod documented
92 ########################################################################
93 0 my ($s) = @_;
94  
95 0 chomp $s;
96  
97 0 $s =~ s/^\s*(.*?)$/$1/xsm;
98  
99 0 return $s;
100 }
101  
102 1 1;
103  
104 __END__
105  
106 =pod
107  
108 =head1 NAME
109  
110 CPAN/Maker/Utils - utilities to support CPAN::Maker
111  
112 =head1 SYNOPSIS
113  
114 use CPAN::Maker::Utils qw(is_core);
115  
116 =head1 DESCRIPTION
117  
118 Set of utilities to support `make-cpan-dist` project.
119  
120 =head1 METHODS AND SUBROUTINES
121  
122 =head2 get_module_version
123  
124 get_module_version(module, [include-paths])
125  
126 If you pass a list
127 of include paths, the function will look for the module in those
128 paths. Returns a hash with information about the module.
129  
130 =over 5
131  
132 =item version
133  
134 The module version. The version is found using
135 C<ExtUtils::MM::parse_version> (this may be an undocumented function
136 not for public consumption).
137  
138 =item module
139  
140 The module name.
141  
142 =item path
143  
144 The fully qualifed path where the module was found.
145  
146 =back
147  
148 =head2 is_core
149  
150 is_core(module, [perl-version])
151  
152 Returns a boolean true value if the module is core. If C<perl-version>
153 is provided it returns true if the module was included in that version
154 of Perl.
155  
156 A module is determined to be core using C<Module::CoreList>.
157  
158 =head2 make_path_from_module
159  
160 make_path_from_module(module)
161  
162 Returns the pathname for module by replacing the double-colon with '/'
163 and adding '.pm' to the end of the string.
164  
165 =head2 trim
166  
167 trim(str)
168  
169 Strip leading whitespace from string.
170  
171 =head1 SEE ALSO
172  
173 L<CPAN::Maker>
174  
175 =head1 AUTHOR
176  
177 Rob Lauer - <rlauer6@comcast.net>
178  
179 =cut
« lib/CPAN/Maker/Role/ModuleUtils.pm ↑ Summary script/make-cpan-dist.pl »