blib/lib/File/Rename/Options.pm

filter: Statementstmt 86.3% 38 / 44 Branchbran 61.1% 11 / 18 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 77.7% 63 / 81 CC 12 SCAR 16.1
CC
12
Cov
76%
GetOptions
8.2
bad_encoding
4.5
import
3.6
CRAP 5.0
« blib/script/rename ↑ Summary Build »
1 package File::Rename::Options;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶BEGIN { eval { require warnings; warnings->import } }
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 our $VERSION = '1.90';
9 14 our $IMPORTED;
10  
11 sub import {
12 14 ▶ my $pack = shift;
Subroutine import: called CC=3 SCAR=12.7
13 14 ▶ if( $IMPORTED++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Rename::Options::IMPORTED++) 0 14 14
14 0 require Carp;
15 0 Carp::cluck("$pack->import() called twice");
16 }
17 14 my @config = qw(
18 posix_default
19 no_ignore_case
20 );
21 14 push @config, @_;
22 14 eval{ Getopt::Long::Configure(@config); 1; }
23 14 ▶ or do { require Carp; Carp::carp($@) };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &Getopt::Long::Configure(@config); 1 } } or do { require Carp; Carp::carp($@) } 0 14 14
24 }
25  
26 sub GetOptions {
27 18 ▶ my ($no_code) = @_;
Subroutine GetOptions: called CC=8 SCAR=21.1
Pod documented
28 18 my @expression;
29 18 my $fullpath = 1;
30 Getopt::Long::GetOptions(
31 '-v|verbose' => \my $verbose,
32 '-0|null' => \my $null,
33 '-n|nono' => \my $nono,
34 '-f|force' => \my $force,
35 '-h|?|help' => \my $help,
36 '-m|man' => \my $man,
37 '-V|version' => \my $version,
38 4 ▶ '-d|filename' => sub { undef $fullpath },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 '-path|fullpath!' => \$fullpath,
40 '-e=s' => \@expression,
41 '-E=s' =>
42 sub {
43 4 ▶ my(undef, $e) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
44 4 $e .= ';';
45 4 push @expression, $e;
46 },
47 18 ▶ '-u|unicode:s' => \my $unicode,
Branch: 1 branch
BranchTrueFalseTotal
&Getopt::Long::GetOptions("-v|verbose", \my $verbose, "-0|null", \my $null, "-n|nono", \my $nono, "-f|force", \my $force, "-h|?|help", \my $help, "-m|man", \my $man, "-V|version", \my $version, "-d|filename", sub { undef $fullpath; } , "-path|fullpath!", \$fullpath, "-e=s", \@expression, "-E=s", sub { my(undef, $e) = @_; $e .= ';'; push @expression, $e; } , "-u|unicode:s", \my $unicode) or return 0 18 18
48 ) or return;
49  
50 18 my $options = {
51 verbose => $verbose,
52 input_null => $null,
53 no_action => $nono,
54 over_write => $force,
55 filename_only => !$fullpath,
56 show_help => $help,
57 show_manual => $man,
58 show_version => $version,
59 unicode_strings => defined $unicode,
60 encoding => $unicode,
61 };
62 18 ▶ return $options if $no_code;
Branch: 1 branch
BranchTrueFalseTotal
if $no_code 6 12 18
63 12 ▶ return $options if $help or $man or $version;
Branch: 1 branch
BranchTrueFalseTotal
if $help or $man or $version 1 11 12
Condition50%3/6
$help or $man or $version
l!l&&r!l&&!r
0111
$help or $man
l!l&&r!l&&!r
0012
MC/DC33%1/3
$help or $man or $version
$help $man $version
Truth table50%2/4
A or B or C
A= $helpB= $manC= $version
ABCresult
1XX1
01X1
0011
0000
64  
65 11 ▶ if( @expression ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@expression) { } 3 8 11
66 3 $options->{_code} = join "\n", @expression;
67 }
68 else {
69 8 ▶ return unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 8 8
70 8 $options->{_code} = shift @ARGV;
71 }
72 11 return $options;
73 }
74  
75 sub bad_encoding {
76 10 ▶ my $options = shift;
Subroutine bad_encoding: called CC=3 SCAR=15.1
Pod documented
77 10 my $encoding = $options->{encoding};
78 10 ▶ return unless $encoding;
Branch: 1 branch
BranchTrueFalseTotal
unless $encoding 10 0 10
79 0 ▶ return unless $encoding =~ /[^\s\w.-]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $encoding =~ /[^\s\w.-]/ 0 0 0
80 0 return 1
81 }
82  
83 14 1;
84 __END__
« blib/script/rename ↑ Summary Build »