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   2826 use strict;
  1         2  
  1         29  
6 1     1   5 use warnings;
  1         2  
  1         24  
7              
8 1     1   633 use Data::Dumper;
  1         7018  
  1         67  
9             $Data::Dumper::Indent = 1;
10              
11 1     1   594 use Moo;
  1         11693  
  1         5  
12             with 'MooX::Role::CliOptions';
13              
14 1     1   1975 use MooX::StrictConstructor;
  1         14411  
  1         35  
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 4415 my $self = shift;
55              
56             # this will trigger the lazy default
57 1 50 33     23 print "running from command line\n" if $self->cli && $self->verbose;
58              
59 1         6 return;
60             }
61              
62             sub run {
63 1     1 0 12670 my $self = shift;
64              
65 1 50       7 printf( "custom_opt: %s\n", $self->custom_opt ) if $self->custom_opt;
66              
67 1 50       8 print Dumper($self) if $self->debug;
68              
69 1         138 return 0;
70             }
71              
72             1;
73             __END__