lib/Pod/Perldoc/GetOptsOO.pm

filter: Statementstmt 42.2% 19 / 45 Branchbran 21.4% 6 / 28 Conditioncond 20.0% 2 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 34.0% 32 / 94 CC 19 SCAR 48.9
CC
19
Cov
33%
getopts
162.4
BEGIN
2.1
BEGIN
1.0
CRAP 133.2
« lib/Pod/Perldoc.pm ↑ Summary lib/Pod/Perldoc/ToTk.pm »
1 package Pod::Perldoc::GetOptsOO;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 $VERSION = '3.28';
6  
7 3 ▶BEGIN { # Make a DEBUG constant ASAP
Subroutine BEGIN: called CC=2 SCAR=7.6
8 *DEBUG = defined( &Pod::Perldoc::DEBUG )
9 ? \&Pod::Perldoc::DEBUG
10 3 ▶ : sub(){10};
Branch: 1 branch
BranchTrueFalseTotal
defined &Pod::Perldoc::DEBUG ? : 3 0 3
11 }
12  
13  
14 2 ▶sub getopts {
Subroutine getopts: called CC=18 SCAR=50.9
Pod documented
15 2 my($target, $args, $truth) = @_;
16  
17 2 ▶ $args ||= \@ARGV;
Condition50%1/2
$args ||= \@ARGV
l!l
20
MC/DC0%0/1
$args ||= \@ARGV
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
18  
19 2 ▶ $target->aside(
Branch: 1 branch
BranchTrueFalseTotal
if $target->can("aside") 2 0 2
20 "Starting switch processing. Scanning arguments [@$args]\n"
21 ) if $target->can('aside');
22  
23 2 ▶ return unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 2 2
24  
25 2 ▶ $truth = 1 unless @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 2 0 2 2
26  
27 2 DEBUG > 3 and print " Truth is $truth\n";
28  
29  
30 2 my $error_count = 0;
31  
32 2 ▶ while( @$args and ($_ = $args->[0]) =~ m/^-(.)(.*)/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args and ($_ = $args->[0]) =~ /^-(.)(.*)/s) 0 2 2
Condition33%1/3
@$args and ($_ = $args->[0]) =~ /^-(.)(.*)/s
!ll&&!rl&&r
020
MC/DC0%0/2
@$args and ($_ = $args->[0]) =~ /^-(.)(.*)/s
@$args ($_ = $args->[0]) =~ /^-(.)(.*)/s
Truth table33%1/3
A and B
A= @$argsB= ($_ = $args->[0]) =~ /^-(.)(.*)/s
ABresult
0X0
100
111
33 0 my($first,$rest) = ($1,$2);
34 0 ▶ if ($_ eq '--') { # early exit if "--"
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "--") 0 0 0
35 0 shift @$args;
36 0 last;
37 }
38 0 ▶ if ($first eq '-' and $rest) { # GNU style long param names
Branch: 1 branch
BranchTrueFalseTotal
if ($first eq "-" and $rest) 0 0 0
Condition0%0/3
$first eq "-" and $rest
!ll&&!rl&&r
000
MC/DC0%0/2
$first eq "-" and $rest
$first eq "-" $rest
Truth table0%0/3
A and B
A= $first eq "-"B= $rest
ABresult
0X0
100
111
39 0 ($first, $rest) = split '=', $rest, 2;
40 }
41 0 my $method = "opt_${first}_with";
42 0 ▶ if( $target->can($method) ) { # it's argumental
Branch: 1 branch
BranchTrueFalseTotal
if ($target->can($method)) { } 0 0 0
43 0 ▶ if($rest eq '') { # like -f bar
Branch: 1 branch
BranchTrueFalseTotal
if ($rest eq '') { } 0 0 0
44 0 shift @$args;
45 0 ▶ $target->warn( "Option $first needs a following argument!\n" ) unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 0 0
46 0 $rest = shift @$args;
47 } else { # like -fbar (== -f bar)
48 0 shift @$args;
49 }
50  
51 0 DEBUG > 3 and print " $method => $rest\n";
52 0 $target->$method( $rest );
53  
54 # Otherwise, it's not argumental...
55 } else {
56  
57 0 ▶ if( $target->can( $method = "opt_$first" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($target->can($method = "opt_$first")) { } 0 0 0
elsif ($target->can('handle_unknown_option')) { } 0 0 0
58 0 DEBUG > 3 and print " $method is true ($truth)\n";
59 0 $target->$method( $truth );
60  
61 # Otherwise it's an unknown option...
62  
63 } elsif( $target->can('handle_unknown_option') ) {
64 0 DEBUG > 3
65 and print " calling handle_unknown_option('$first')\n";
66  
67 0 ▶ $error_count += (
Condition0%0/2
$target->handle_unknown_option($first) || 0
l!l
00
MC/DC0%0/1
$target->handle_unknown_option($first) || 0
$target->handle_unknown_option($first)
Truth table0%0/2
A
A= $target->handle_unknown_option($first)
Aresult
11
00
68 $target->handle_unknown_option( $first ) || 0
69 );
70  
71 } else {
72 0 ++$error_count;
73 0 $target->warn( "Unknown option: $first\n" );
74 }
75  
76 0 ▶ if($rest eq '') { # like -f
Branch: 1 branch
BranchTrueFalseTotal
if ($rest eq '') { } 0 0 0
77 0 shift @$args
78 } else { # like -fbar (== -f -bar )
79 0 DEBUG > 2 and print " Setting args->[0] to \"-$rest\"\n";
80 0 $args->[0] = "-$rest";
81 }
82 }
83 }
84  
85  
86 $target->aside(
87 2 ▶ "Ending switch processing. Args are [@$args] with $error_count errors.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $target->can("aside") 2 0 2
88 ) if $target->can('aside');
89  
90 2 $error_count == 0;
91 }
92  
93 3 1;
94  
95 __END__
« lib/Pod/Perldoc.pm ↑ Summary lib/Pod/Perldoc/ToTk.pm »