| 1 | # ============================================================================« | ||||||||||||||||||||||||||||||||||
| 2 | package MooseX::App; | ||||||||||||||||||||||||||||||||||
| 3 | # ============================================================================« | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 11 | our $AUTHORITY = 'cpan:MAROS'; | |||||||||||||||||||||||||||||||||
| 11 | 11 | our $VERSION = '1.43'; | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use MooseX::App::Meta::Role::Attribute::Option; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use MooseX::App::Exporter qw(app_usage app_description app_base app_fuzzy app_strict app_prefer_commandline app_permute option parameter); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use MooseX::App::Message::Envelope; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Moose::Exporter; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 11 | my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods( | |||||||||||||||||||||||||||||||||
| 20 | with_meta => [ qw(app_usage app_description app_namespace app_exclude app_base app_fuzzy app_command_name app_command_register app_strict app_prefer_commandline option parameter app_permute) ], | ||||||||||||||||||||||||||||||||||
| 21 | also => [ 'Moose' ], | ||||||||||||||||||||||||||||||||||
| 22 | as_is => [ 'new_with_command' ], | ||||||||||||||||||||||||||||||||||
| 23 | install => [ 'unimport','init_meta' ], | ||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | sub import { | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 27 | 12 | my ( $class, @plugins ) = @_; | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | # Get caller | ||||||||||||||||||||||||||||||||||
| 30 | 12 | my ($caller_class) = caller(); | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # Process plugins | ||||||||||||||||||||||||||||||||||
| 33 | 12 | MooseX::App::Exporter->process_plugins($caller_class,@plugins); | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | # Call Moose-Exporter generated importer | ||||||||||||||||||||||||||||||||||
| 36 | 12 | return $class->$IMPORT( { into => $caller_class } ); | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | sub init_meta { | ||||||||||||||||||||||||||||||||
|
Subroutine
init_meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 12 | my ($class,%args) = @_; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | # Get required roles and metaroles | ||||||||||||||||||||||||||||||||||
| 43 | 12 | $args{roles} = ['MooseX::App::Role::Base']; | |||||||||||||||||||||||||||||||||
| 44 | $args{metaroles} = { | ||||||||||||||||||||||||||||||||||
| 45 | 12 | class => [ | |||||||||||||||||||||||||||||||||
| 46 | 'MooseX::App::Meta::Role::Class::Base', | ||||||||||||||||||||||||||||||||||
| 47 | 'MooseX::App::Meta::Role::Class::Documentation' | ||||||||||||||||||||||||||||||||||
| 48 | ], | ||||||||||||||||||||||||||||||||||
| 49 | attribute => [ | ||||||||||||||||||||||||||||||||||
| 50 | 'MooseX::App::Meta::Role::Attribute::Option' | ||||||||||||||||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 12 | return MooseX::App::Exporter->process_init_meta(%args); | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | sub app_command_name(&) { | ||||||||||||||||||||||||||||||||
|
Subroutine
app_command_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 58 | 3 | my ( $meta, $namesub ) = @_; | |||||||||||||||||||||||||||||||||
| 59 | 3 | return $meta->app_command_name($namesub); | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub app_command_register(%) { | ||||||||||||||||||||||||||||||||
|
Subroutine
app_command_register: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 63 | 0 | my ( $meta, %commands ) = @_; | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 0 | foreach my $command (keys %commands) { | |||||||||||||||||||||||||||||||||
| 66 | 0 | $meta->command_register($command,$commands{$command}); | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub app_namespace(@) { | ||||||||||||||||||||||||||||||||
|
Subroutine
app_namespace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | my ( $meta, @namespaces ) = @_; | |||||||||||||||||||||||||||||||||
| 73 | 0 | return $meta->app_namespace( \@namespaces ); | |||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub app_exclude(@) { | ||||||||||||||||||||||||||||||||
|
Subroutine
app_exclude: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 77 | 3 | my ( $meta, @namespaces ) = @_; | |||||||||||||||||||||||||||||||||
| 78 | 3 | return $meta->app_exclude( \@namespaces ); | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 71 | ▶ | sub new_with_command { | ||||||||||||||||||||||||||||||||
|
Subroutine
new_with_command: called CC=18 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 82 | 71 | my ($class,@args) = @_; | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 71 | ▶ | Moose->throw_error('new_with_command is a class method') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $class or builtin::blessed($class)
MC/DC50%1/2
not defined $class or builtin::blessed($class)
not defined $class
builtin::blessed($class)
Truth table66%2/3
not(A) or B
A= not defined $classB= builtin::blessed($class)
| |||||||||||||||||||||||||||||||||||
| 85 | if ! defined $class || blessed($class); | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 70 | my $meta = $class->meta; | |||||||||||||||||||||||||||||||||
| 88 | 70 | my $metameta = $meta->meta; | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | # Sanity check | ||||||||||||||||||||||||||||||||||
| 91 | 70 | ▶ | Moose->throw_error('new_with_command may only be called from the application base package:'.$class) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$metameta->does_role("MooseX::App::Meta::Role::Class::Command") or not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
MC/DC50%1/2
$metameta->does_role("MooseX::App::Meta::Role::Class::Command") or not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
$metameta->does_role("MooseX::App::Meta::Role::Class::Command")
not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
Truth table66%2/3
A or not(B)
A= $metameta->does_role("MooseX::App::Meta::Role::Class::Command")B= not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
| |||||||||||||||||||||||||||||||||||
| 92 | if $metameta->does_role('MooseX::App::Meta::Role::Class::Command') | ||||||||||||||||||||||||||||||||||
| 93 | || ! $metameta->does_role('MooseX::App::Meta::Role::Class::Base'); | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | $meta->command_check() | ||||||||||||||||||||||||||||||||||
| 96 | 69 | ▶ | if $ENV{APP_DEVELOPER} || $ENV{HARNESS_ACTIVE}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"APP_DEVELOPER"} or $ENV{"HARNESS_ACTIVE"}
MC/DC0%0/2
$ENV{"APP_DEVELOPER"} or $ENV{"HARNESS_ACTIVE"}
$ENV{"APP_DEVELOPER"}
$ENV{"HARNESS_ACTIVE"}
Truth table33%1/3
A or B
A= $ENV{"APP_DEVELOPER"}B= $ENV{"HARNESS_ACTIVE"}
| |||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | # Extra args | ||||||||||||||||||||||||||||||||||
| 99 | 69 | my %args; | |||||||||||||||||||||||||||||||||
| 100 | 69 | ▶ | if (scalar @args == 1 | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "HASH"
scalar @args == 1
ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 101 | && ref($args[0]) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||
| 102 | 0 | %args = %{$args[0]}; | |||||||||||||||||||||||||||||||||
| 103 | } elsif (scalar @args % 2 == 0) { | ||||||||||||||||||||||||||||||||||
| 104 | 68 | %args = @args; | |||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||
| 106 | 1 | Moose->throw_error('new_with_command got invalid extra arguments'); | |||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | # Get ARGV | ||||||||||||||||||||||||||||||||||
| 110 | 68 | my $argv = delete $args{ARGV}; | |||||||||||||||||||||||||||||||||
| 111 | 68 | my $parsed_argv; | |||||||||||||||||||||||||||||||||
| 112 | 68 | ▶ | if (defined $argv) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | 7 | $parsed_argv = MooseX::App::ParsedArgv->new( argv => $argv ); | |||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||
| 115 | 61 | $parsed_argv = MooseX::App::ParsedArgv->instance(); | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 68 | my $first_argv = $parsed_argv->first_argv; | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | # Requested help | ||||||||||||||||||||||||||||||||||
| 121 | 68 | ▶ | if (defined $first_argv | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $first_argv and lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
MC/DC100%2/2
defined $first_argv and lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
defined $first_argv
lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
Truth table100%3/3
A and B
A= defined $first_argvB= lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
| |||||||||||||||||||||||||||||||||||
| 122 | && lc($first_argv) =~ m/^(help|h|\?|usage|-h|--help|-\?|--usage)$/) { | ||||||||||||||||||||||||||||||||||
| 123 | 2 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||||||||||||||||
| 124 | $meta->command_usage_global(), | ||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||
| 126 | # No args | ||||||||||||||||||||||||||||||||||
| 127 | ▶ | } elsif (! defined $first_argv | |||||||||||||||||||||||||||||||||
|
Condition66%4/6
not defined $first_argv or $first_argv =~ /^\s*$/ or $first_argv =~ /^-{1,2}\w/
not defined $first_argv or $first_argv =~ /^\s*$/
MC/DC33%1/3
not defined $first_argv or $first_argv =~ /^\s*$/ or $first_argv =~ /^-{1,2}\w/
not defined $first_argv
$first_argv =~ /^\s*$/
$first_argv =~ /^-{1,2}\w/
Truth table50%2/4
not(A) or B or C
A= not defined $first_argvB= $first_argv =~ /^\s*$/C= $first_argv =~ /^-{1,2}\w/
| |||||||||||||||||||||||||||||||||||
| 128 | || $first_argv =~ m/^\s*$/ | ||||||||||||||||||||||||||||||||||
| 129 | || $first_argv =~ m/^-{1,2}\w/) { | ||||||||||||||||||||||||||||||||||
| 130 | 2 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||||||||||||||||
| 131 | $meta->command_message( | ||||||||||||||||||||||||||||||||||
| 132 | header => "Missing command", # LOCALIZE | ||||||||||||||||||||||||||||||||||
| 133 | type => "error", | ||||||||||||||||||||||||||||||||||
| 134 | ), | ||||||||||||||||||||||||||||||||||
| 135 | $meta->command_usage_global(), | ||||||||||||||||||||||||||||||||||
| 136 | 127, # exitcode | ||||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||||
| 138 | # Looks like a command | ||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||
| 140 | 64 | my $return = $meta->command_find(); | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | # Nothing found | ||||||||||||||||||||||||||||||||||
| 143 | 64 | ▶ | if (blessed $return | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($return) and $return->isa("MooseX::App::Message::Block")
MC/DC50%1/2
builtin::blessed($return) and $return->isa("MooseX::App::Message::Block")
builtin::blessed($return)
$return->isa("MooseX::App::Message::Block")
Truth table66%2/3
A and B
A= builtin::blessed($return)B= $return->isa("MooseX::App::Message::Block")
| |||||||||||||||||||||||||||||||||||
| 144 | && $return->isa('MooseX::App::Message::Block')) { | ||||||||||||||||||||||||||||||||||
| 145 | 2 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||||||||||||||||
| 146 | $return, | ||||||||||||||||||||||||||||||||||
| 147 | $meta->command_usage_global(), | ||||||||||||||||||||||||||||||||||
| 148 | 127, # exitcode | ||||||||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||||||||
| 150 | # One command found | ||||||||||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||||||||
| 152 | 62 | my $command_class = $meta->command_get($return); | |||||||||||||||||||||||||||||||||
| 153 | 62 | return $class->initialize_command_class($command_class,%args); | |||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 11 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 160 | 11 | 1; | |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||||||||