lib/File/Rename/Options.pm

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