| 1 | package App::BCSSH::Options; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strictures 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | use Package::Variant | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | importing => ['Moo::Role'], | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | subs => [ qw(has around before after with) ], | ||||||||||||||||||||||||||||
| 6 | 1 | ; | |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use App::BCSSH::Options::Accessor as => 'OptAccessor'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use MooX::CaptainHook qw(on_application); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | sub make_variant { | ||||||||||||||||||||||||||
|
Subroutine
make_variant: called CC=5 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 4 | my ($class, $target_package, %in_config) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | my $error = delete $in_config{'-error'} || $class->default_error; | ||||||||||||||||||||||||||
|
Condition33%1/3
delete $in_config{'-error'} || $class->default_error
MC/DC0%0/2
delete $in_config{'-error'} || $class->default_error
delete $in_config{'-error'}
$class->default_error
Truth table33%1/3
A || B
A= delete $in_config{'-error'}B= $class->default_error
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | my $arg_error = delete $in_config{'-arg_error'} || $class->default_arg_error; | ||||||||||||||||||||||||||
|
Condition33%1/3
delete $in_config{'-arg_error'} || $class->default_arg_error
MC/DC0%0/2
delete $in_config{'-arg_error'} || $class->default_arg_error
delete $in_config{'-arg_error'}
$class->default_arg_error
Truth table33%1/3
A || B
A= delete $in_config{'-arg_error'}B= $class->default_arg_error
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | my $config = $class->default_config; | |||||||||||||||||||||||||||
| 18 | 4 | for my $opt (keys %in_config) { | |||||||||||||||||||||||||||
| 19 | $config->{$opt} = $in_config{$opt} | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | if exists $config->{$opt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | my %arguments; | |||||||||||||||||||||||||||
| 24 | 4 | ▶ | on_application { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 4 | my $target = $_; | |||||||||||||||||||||||||||
| 26 | Moo::Role->apply_roles_to_object( | ||||||||||||||||||||||||||||
| 27 | Moo->_accessor_maker_for($target), | ||||||||||||||||||||||||||||
| 28 | 4 | ▶ | OptAccessor(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 4 | my ($into, $name, $spec) = @_; | |||||||||||||||||||||||||||
| 30 | 4 | $arguments{$name} = $spec; | |||||||||||||||||||||||||||
| 31 | 4 | }), | |||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | 4 | } $target_package; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | my $parser; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | install _parse => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | $parser ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$parser ||= do {
require Getopt::Long;
"Getopt::Long::Parser"->new("config", ["default", map({$_ =~ /_pattern$/ ? "$_=$config->{$_}" : ($config->{$_} ? $_ : "no_$_");} keys %$config)])
}
MC/DC0%0/2
$parser ||= do {
require Getopt::Long;
"Getopt::Long::Parser"->new("config", ["default", map({$_ =~ /_pattern$/ ? "$_=$config->{$_}" : ($config->{$_} ? $_ : "no_$_");} keys %$config)])
}
$parser
do {
require Getopt::Long;
"Getopt::Long::Parser"->new("config", ["default", map({$_ =~ /_pattern$/ ? "$_=$config->{$_}" : ($config->{$_} ? $_ : "no_$_");} keys %$config)])
}
Truth table0%0/3
A ||= B
A= $parserB= do {
require Getopt::Long;
"Getopt::Long::Parser"->new("config", ["default", map({$_ =~ /_pattern$/ ? "$_=$config->{$_}" : ($config->{$_} ? $_ : "no_$_");} keys %$config)])
}
| |||||||||||||||||||||||||||||
| 39 | 0 | require Getopt::Long; | |||||||||||||||||||||||||||
| 40 | Getopt::Long::Parser->new(config => [ | ||||||||||||||||||||||||||||
| 41 | 'default', | ||||||||||||||||||||||||||||
| 42 | map { | ||||||||||||||||||||||||||||
| 43 | 0 | $_ =~ /_pattern$/ ? "$_=$config->{$_}" | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | : $config->{$_} ? $_ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 45 | : "no_$_" | ||||||||||||||||||||||||||||
| 46 | } keys %$config | ||||||||||||||||||||||||||||
| 47 | ]); | ||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my %opts; | |||||||||||||||||||||||||||
| 51 | my @parse_args = map { | ||||||||||||||||||||||||||||
| 52 | 0 | ("$arguments{$_}" => \($opts{$_})) | |||||||||||||||||||||||||||
| 53 | } keys %arguments; | ||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 0 | local @ARGV = @$args; | |||||||||||||||||||||||||||
| 56 | 0 | local $SIG{__WARN__} = $arg_error; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | $parser->getoptions(@parse_args) or $error->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | @$args = @ARGV; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | for my $k (keys %opts) { | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | delete $opts{$k} if !defined $opts{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($config->{passthrough}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | for my $idx (0..$#$args) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($args->[$idx] eq '--') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | splice @$args, $idx, 1; | |||||||||||||||||||||||||||
| 67 | 0 | last; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | return \%opts; | |||||||||||||||||||||||||||
| 72 | 4 | }; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | has args => (is => 'ro', default => sub { [] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 77 | 0 | my $orig = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (@_ == 1 && ref $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0]
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||
| 80 | 0 | return $class->$orig(@_); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | my $args = [@_]; | |||||||||||||||||||||||||||
| 83 | 0 | my $opts = $class->_parse($args); | |||||||||||||||||||||||||||
| 84 | 0 | $opts->{args} = $args; | |||||||||||||||||||||||||||
| 85 | 0 | return $class->$orig($opts); | |||||||||||||||||||||||||||
| 86 | 4 | }; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | ▶ | sub default_config {{ | ||||||||||||||||||||||||||
|
Subroutine
default_config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 4 | auto_abbrev => 0, | |||||||||||||||||||||||||||
| 91 | gnu_compat => 1, | ||||||||||||||||||||||||||||
| 92 | permute => 0, | ||||||||||||||||||||||||||||
| 93 | bundling => 1, | ||||||||||||||||||||||||||||
| 94 | bundling_override => 0, | ||||||||||||||||||||||||||||
| 95 | ignore_case => 0, | ||||||||||||||||||||||||||||
| 96 | ignore_case_always => 0, | ||||||||||||||||||||||||||||
| 97 | pass_through => 1, | ||||||||||||||||||||||||||||
| 98 | prefix_pattern => '--|-', | ||||||||||||||||||||||||||||
| 99 | long_prefix_pattern => '--', | ||||||||||||||||||||||||||||
| 100 | debug => 0, | ||||||||||||||||||||||||||||
| 101 | }} | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | sub default_error { | ||||||||||||||||||||||||||
|
Subroutine
default_error: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub { die "Bad arguments!\n" } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 105 | 4 | } | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 4 | ▶ | sub default_arg_error { | ||||||||||||||||||||||||||
|
Subroutine
default_arg_error: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub { warn $_[0] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 109 | 4 | } | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | 1; | |||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||