| 1 | package Getopt::Yath; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '2.000007'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Getopt::Yath::Util qw/mod2file/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Getopt::Yath::Instance; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Getopt::Yath::Option; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub import { | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||
| 16 | 1 | my %params = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | my $caller = caller(); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | my $inst_class = $params{inst_class} // 'Getopt::Yath::Instance'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params{"inst_class"} // "Getopt::Yath::Instance"
MC/DC0%0/1
$params{"inst_class"} // "Getopt::Yath::Instance"
$params{"inst_class"}
Truth table50%1/2
A
A= $params{"inst_class"}
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my $instance = $inst_class->new(class => $class); | |||||||||||||||||||||||||||
| 23 | 1 | ▶ | $instance->include($class->options) if $params{inherit} && $class->can('options'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params{"inherit"} and $class->can("options")
MC/DC0%0/2
$params{"inherit"} and $class->can("options")
$params{"inherit"}
$class->can("options")
Truth table33%1/3
A and B
A= $params{"inherit"}B= $class->can("options")
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | my %export; | |||||||||||||||||||||||||||
| 26 | my @common; | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $export{options} = sub { $instance }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $export{option} = sub { | ||||||||||||||||||||||||||||
| 30 | 16 | ▶ | my $title = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 31 | 16 | ▶ | my $option = Getopt::Yath::Option->create(trace => [caller()], title => $title, @common ? (%{$common[-1]}) : (), @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 15 | $instance->_option($option); | |||||||||||||||||||||||||||
| 33 | 1 | }; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | $export{include_options} = sub { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | while (my $module = shift @_) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | my $file = mod2file($module); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | require $file unless $INC{$file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | croak "Module '$module' does not have an 'options' method" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | unless $module->can('options'); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $list = @_ && ref($_[0]) eq 'ARRAY' ? shift(@_) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and ref $_[0] eq "ARRAY"
MC/DC0%0/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $instance->include($module->options, $list); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 1 | }; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | $export{option_post_process} = sub { | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | my $cb = pop; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | my $weight = shift // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // 0
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 52 | 4 | my ($applicable) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | $applicable //= $common[-1]->{applicable} if @common; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$applicable //= $common[-1]{"applicable"}
MC/DC0%0/2
$applicable //= $common[-1]{"applicable"}
$applicable
$common[-1]{"applicable"}
Truth table33%1/3
A //= B
A= $applicableB= $common[-1]{"applicable"}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | croak "You must provide a callback coderef" unless $cb && ref($cb) eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cb and ref $cb eq "CODE"
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb
ref $cb eq "CODE"
Truth table33%1/3
A and B
A= $cbB= ref $cb eq "CODE"
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | $instance->_post([caller()], $weight, $applicable, $cb); | |||||||||||||||||||||||||||
| 59 | 1 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | $export{option_group} = sub { | ||||||||||||||||||||||||||||
| 62 | 2 | ▶ | my ($set, $sub) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | my $common = {@common ? (%{$common[-1]}) : (), %$set}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | $common->{module} = caller unless $common->{no_module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | push @common => $common; | |||||||||||||||||||||||||||
| 69 | 2 | my $ok = eval { $sub->(); 1 }; | |||||||||||||||||||||||||||
| 70 | 2 | my $err = $@; | |||||||||||||||||||||||||||
| 71 | 2 | pop @common; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | die $err unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 1 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | $export{parse_options} = sub { $instance->process_args(@_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $export{category_sort_map} = sub { $instance->set_category_sort_map(@_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | for my $name (keys %export) { | |||||||||||||||||||||||||||
| 81 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | croak "$caller already has an '$name' method" | ||||||||||||||||||||||||||||
| 83 | 7 | ▶ | if defined(&{"${caller}\::${name}"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 7 | *{"${caller}\::${name}"} = $export{$name}; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | return 1; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||