line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Command::Template::Instance; |
2
|
3
|
|
|
3
|
|
55
|
use 5.024000; |
|
3
|
|
|
|
|
18
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
4
|
3
|
|
|
3
|
|
17
|
use experimental qw< signatures >; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
16
|
|
5
|
3
|
|
|
3
|
|
322
|
no warnings qw< experimental::signatures >; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
217
|
|
6
|
|
|
|
|
|
|
{ our $VERSION = '0.001' } |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2120
|
use Storable 'dclone'; |
|
3
|
|
|
|
|
10081
|
|
|
3
|
|
|
|
|
2163
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# accessors |
11
|
10
|
|
|
10
|
1
|
21
|
sub defaults ($self, @new) { |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
18
|
|
12
|
10
|
50
|
|
|
|
638
|
return dclone($self->{defaults}) unless @new; |
13
|
0
|
|
|
|
|
0
|
$self->{defaults} = $new[0]; |
14
|
0
|
|
|
|
|
0
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
10
|
|
|
10
|
1
|
21
|
sub template ($self) { dclone($self->{template}) } |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
388
|
|
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
10
|
1
|
2180
|
sub generate ($self, %bindings) {; |
|
10
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
40
|
|
|
10
|
|
|
|
|
18
|
|
19
|
10
|
|
|
|
|
54
|
my $defaults = $self->defaults; |
20
|
10
|
|
|
|
|
43
|
my @command; |
21
|
10
|
|
|
|
|
63
|
for my $arg ($self->template->@*) { |
22
|
44
|
100
|
|
|
|
130
|
if (! ref $arg) { |
23
|
10
|
|
|
|
|
64
|
push @command, $arg; |
24
|
10
|
|
|
|
|
26
|
next; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
34
|
|
|
|
|
59
|
my ($name, $default, $type) = @{$arg}{qw< name default type >}; |
|
34
|
|
|
|
|
84
|
|
28
|
|
|
|
|
|
|
my $value = |
29
|
|
|
|
|
|
|
exists $bindings{$name} ? $bindings{$name} |
30
|
34
|
100
|
|
|
|
108
|
: exists $defaults->{$name} ? $defaults->{$name} |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
31
|
|
|
|
|
|
|
: defined $default ? $default |
32
|
|
|
|
|
|
|
: undef; |
33
|
34
|
100
|
|
|
|
65
|
if (defined $value) { |
34
|
29
|
50
|
|
|
|
66
|
push @command, ref($value) eq 'ARRAY' ? (@$value) : $value; |
35
|
29
|
|
|
|
|
55
|
next; |
36
|
|
|
|
|
|
|
} |
37
|
5
|
50
|
|
|
|
19
|
die "missing required parameter '$name'\n" if $type eq 'req'; |
38
|
|
|
|
|
|
|
} |
39
|
10
|
50
|
|
|
|
69
|
return wantarray ? @command : \@command; |
40
|
|
|
|
|
|
|
} ## end sub expand |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
2
|
1
|
5
|
sub new ($package, @input_command) { |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
4
|
|
43
|
2
|
|
|
|
|
5
|
my @command; |
44
|
2
|
|
|
|
|
5
|
for my $arg (@input_command) { |
45
|
9
|
50
|
|
|
|
23
|
die "invalid parameter: undefined\n" unless defined $arg; |
46
|
9
|
50
|
|
|
|
18
|
die "invalid parameter: plain scalars only\n" if ref $arg; |
47
|
|
|
|
|
|
|
|
48
|
9
|
50
|
|
|
|
24
|
if (length($arg) == 0) { |
49
|
0
|
|
|
|
|
0
|
push @command, ''; |
50
|
0
|
|
|
|
|
0
|
next; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
9
|
|
|
|
|
20
|
my $first_char = substr $arg, 0, 1; |
54
|
9
|
50
|
100
|
|
|
46
|
if ($first_char eq '\\') { |
|
|
100
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
push @command, substr $arg, 1; |
56
|
0
|
|
|
|
|
0
|
next; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($first_char ne '<' && $first_char ne '[') { |
59
|
2
|
|
|
|
|
5
|
push @command, $arg; |
60
|
2
|
|
|
|
|
7
|
next; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
7
|
100
|
|
|
|
23
|
my ($type, $lc) = $first_char eq '<' ? ('req', '>') : ('opt', ']'); |
64
|
7
|
50
|
|
|
|
171
|
my ($name, $default) = $arg =~ m{ |
65
|
|
|
|
|
|
|
\A \Q$first_char\E |
66
|
|
|
|
|
|
|
([a-zA-Z_]\w+) # name, starts with no digit |
67
|
|
|
|
|
|
|
(?: = (.*))? # optional default value |
68
|
|
|
|
|
|
|
\Q$lc\E \z |
69
|
|
|
|
|
|
|
}mxs or die "invalid parameter {$arg}\n"; |
70
|
7
|
|
|
|
|
39
|
push @command, |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
default => $default, |
73
|
|
|
|
|
|
|
name => $name, |
74
|
|
|
|
|
|
|
type => $type, |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
} ## end for my $arg (@_) |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
25
|
return bless { defaults => {}, template => \@command }, $package; |
79
|
|
|
|
|
|
|
} ## end sub _parse_command |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |