File Coverage

samples/1-methods/lib/GreetingsClass.pm
Criterion Covered Total %
statement 5 12 41.6
branch 0 2 0.0
condition 0 5 0.0
subroutine 2 3 66.6
pod 0 1 0.0
total 7 23 30.4


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2 1     1   714 use v5.38;
  1         5  
3 1     1   7 use experimental 'class';
  1         2  
  1         9  
4              
5             class GreetingsClass;
6              
7             field $name :param;
8              
9             method hello {
10             join " ", "Hello", $name;
11             };
12              
13             method hi {
14             join " ", "Hi", $name;
15             };
16              
17             sub parse_args {
18 0     0 0   my ($pack, $argList) = @_;
19 0           my @args;
20 0   0       while (@$argList and $argList->[0] =~ m{
21             ^--
22             (?:
23             (?[-\w]+)
24             (?:
25             =
26             (?.*)
27             )?
28             )?
29             \z
30             }xs) {
31 0           shift @$argList;
32 0 0         last if $& eq "--";
33 0   0       push @args, $+{name}, $+{value} // 1;
34             }
35 0           @args;
36             }
37              
38             unless (caller) {
39             my @params = __PACKAGE__->parse_args(\@ARGV);
40              
41             my $cmd = shift @ARGV
42             or die "Usage: $0 COMMAND ARGS...\n";
43              
44             my $self = __PACKAGE__->new(name => "world", @params);
45              
46             if (my $sub = $self->can("cmd_$cmd")) {
47             $sub->($self, @ARGV)
48             }
49             elsif ($sub = $self->can("$cmd")) {
50             print $self->$cmd(@ARGV), "\n";
51             }
52             else {
53             die "Unknown command: $cmd\n";
54             }
55             }
56              
57             1;
58