| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package My::Moodulino; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | with 'MooX::Role::CliOptions'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use MooX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | my $cli = 0; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | has custom_opt => ( is => 'ro', ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | has internal_attr => ( | |||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | init_arg => undef, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has cli => ( | ||||||||||||||||||||||||||||
| 26 | is => 'lazy', | ||||||||||||||||||||||||||||
| 27 | init_arg => undef, | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | default => sub { return $cli; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # all attributes and package variable MUST be declared before this! | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | print "caller-stack is empty\n"; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # set this so test scripts can see it in the attribute | ||||||||||||||||||||||||||||
| 36 | 0 | $cli = 1; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $app = __PACKAGE__->init( | |||||||||||||||||||||||||||
| 39 | argv => \@ARGV, | ||||||||||||||||||||||||||||
| 40 | add_opts => ['custom_opt=s'], | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | exit $app->run; | |||||||||||||||||||||||||||
| 44 | } unless caller(); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # executable code like this should not be used in actual scripts, this | ||||||||||||||||||||||||||||
| 47 | # is only here to provide data for the tests. | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | print "command line flag not set\n" if !$cli; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | print "exit was not called\n"; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # BUILD will be called like normal if present as part of 'init', shown | ||||||||||||||||||||||||||||
| 52 | # here for illustration purposes only. | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # this will trigger the lazy default | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | print "running from command line\n" if $self->cli && $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->cli and $self->verbose
MC/DC0%0/2
$self->cli and $self->verbose
$self->cli
$self->verbose
Truth table33%1/3
A and B
A= $self->cliB= $self->verbose
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | printf( "custom_opt: %s\n", $self->custom_opt ) if $self->custom_opt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | print Dumper($self) if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | return 0; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | 1; | |||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||