File Coverage

samples/2-options/lib/Greetings_oo_modulino_with_fields.pm
Criterion Covered Total %
statement 9 23 39.1
branch 0 2 0.0
condition 0 5 0.0
subroutine 3 7 42.8
pod 0 3 0.0
total 12 40 30.0


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2             package
3             Greetings_oo_modulino_with_fields;
4 4     4   1778 use strict;
  4         23  
  4         238  
5 4     4   26 use warnings;
  4         8  
  4         256  
6              
7 4     4   68 use fields qw/name no-thanx x y/;
  4         33  
  4         38  
8             sub MY () {__PACKAGE__}
9              
10             unless (caller) {
11             my $self = MY->new(name => 'world', MY->_parse_posix_opts(\@ARGV));
12              
13             my $cmd = shift
14             or die "Usage: $0 COMMAND ARGS...\n";
15              
16             print $self->$cmd(@ARGV), "\n";
17             }
18              
19             sub _parse_posix_opts {
20 0     0     my ($class, $list) = @_;
21 0           my @opts;
22 0   0       while (@$list and $list->[0] =~ /^--(?:(\w+)(?:=(.*))?)?\z/s) {
23 0           shift @$list;
24 0 0         last unless defined $1;
25 0   0       push @opts, $1, $2 // 1;
26             }
27 0           @opts;
28             }
29              
30 0     0 0   sub new { my MY $self = fields::new(shift); %$self = @_; $self }
  0            
  0            
31              
32 0     0 0   sub hello { my MY $self = shift; join " ", "Hello", $self->{name} }
  0            
33              
34 0     0 0   sub goodnight { my MY $self = shift; join(" ", "Good night" => $self->{name}, @_)}
  0            
35              
36             1;