File Coverage

examples/moodulino.pl
Criterion Covered Total %
statement 22 22 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 2 0.0
total 33 40 82.5


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package My::Moodulino;
4              
5 1     1   184844 use strict;
  1         3  
  1         30  
6 1     1   5 use warnings;
  1         2  
  1         31  
7              
8 1     1   516 use Data::Dumper;
  1         7442  
  1         82  
9             $Data::Dumper::Indent = 1;
10              
11 1     1   543 use Moo;
  1         9482  
  1         4  
12             with 'MooX::Role::CliOptions';
13              
14 1     1   1595 use MooX::StrictConstructor;
  1         11196  
  1         4  
15              
16             my $cli = 0;
17              
18             has custom_opt => ( is => 'ro', );
19              
20             has internal_attr => (
21             is => 'rw',
22             init_arg => undef,
23             );
24              
25             has cli => (
26             is => 'lazy',
27             init_arg => undef,
28             default => sub { return $cli; },
29             );
30              
31             # all attributes and package variable MUST be declared before this!
32             do {
33             print "caller-stack is empty\n";
34              
35             # set this so test scripts can see it in the attribute
36             $cli = 1;
37              
38             my $app = __PACKAGE__->init(
39             argv => \@ARGV,
40             add_opts => ['custom_opt=s'],
41             );
42              
43             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             print "command line flag not set\n" if !$cli;
49             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             sub BUILD {
54 1     1 0 3605 my $self = shift;
55              
56             # this will trigger the lazy default
57 1 50 33     18 print "running from command line\n" if $self->cli && $self->verbose;
58              
59 1         5 return;
60             }
61              
62             sub run {
63 1     1 0 10334 my $self = shift;
64              
65 1 50       5 printf( "custom_opt: %s\n", $self->custom_opt ) if $self->custom_opt;
66              
67 1 50       7 print Dumper($self) if $self->debug;
68              
69 1         118 return 0;
70             }
71              
72             1;
73             __END__