line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Presto::ArgProcessor; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:MPERRY'; |
3
|
|
|
|
|
|
|
$App::Presto::ArgProcessor::VERSION = '0.010'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Term::ShellUI sub-class |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
13583
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
447
|
use Regexp::Common 2013030901 qw(balanced); |
|
1
|
|
|
|
|
3473
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
1607
|
use Moo; |
|
1
|
|
|
|
|
10419
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
1571
|
use File::Slurp qw(read_file); |
|
1
|
|
|
|
|
9846
|
|
|
1
|
|
|
|
|
740
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has _stash => ( |
13
|
|
|
|
|
|
|
is => 'lazy', |
14
|
|
|
|
|
|
|
handles => ['stash'], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
sub _build__stash { |
17
|
0
|
|
|
0
|
|
0
|
return App::Presto->instance->_stash; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has client => ( |
21
|
|
|
|
|
|
|
is => 'lazy', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _build_client { |
25
|
0
|
|
|
0
|
|
0
|
return App::Presto->instance->client; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has config => ( |
29
|
|
|
|
|
|
|
is => 'lazy', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_config { |
33
|
0
|
|
|
0
|
|
0
|
return App::Presto->instance->config; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has term => ( |
37
|
|
|
|
|
|
|
is => 'lazy', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _build_term { |
41
|
0
|
|
|
0
|
|
0
|
return App::Presto->instance->term; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub process { |
45
|
14
|
|
|
14
|
0
|
2886
|
my $self = shift; |
46
|
14
|
|
|
|
|
14
|
my $args = shift; |
47
|
14
|
|
|
|
|
14
|
foreach my $i ( 0 .. $#{$args} ) { |
|
14
|
|
|
|
|
37
|
|
48
|
39
|
|
|
|
|
976
|
my $arg = $args->[$i]; |
49
|
39
|
50
|
|
|
|
166
|
if ( $arg =~ m{^#} ) { # comments |
|
|
100
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
splice( @$args, $i ); # everything else is a comment |
51
|
0
|
|
|
|
|
0
|
last; |
52
|
|
|
|
|
|
|
} elsif ( $arg =~ m[^(\$$RE{balanced}{-keep})$] ) { # full substitutions |
53
|
8
|
|
|
|
|
618
|
$args->[$i] = $self->_expand_param( substr( $2, 1, -1 ), $1 ); |
54
|
|
|
|
|
|
|
} else { # this one gets interpolated |
55
|
31
|
100
|
|
|
|
2509
|
$args->[$i] =~ s[(\$$RE{balanced}{-keep})][my $result = $self->_expand_param(substr($2,1,-1),$1); ref($result) eq 'ARRAY' ? join(',', @$result) : $result]eg; |
|
4
|
|
|
|
|
303
|
|
|
4
|
|
|
|
|
50
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
14
|
|
|
|
|
957
|
return $args; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _expand_param { |
62
|
12
|
|
|
12
|
|
17
|
my $self = shift; |
63
|
12
|
|
|
|
|
26
|
my $param = shift; |
64
|
12
|
|
|
|
|
12
|
my $orig = shift; |
65
|
12
|
|
|
|
|
9
|
my $replacement = ''; |
66
|
12
|
100
|
|
|
|
50
|
if($param =~ m/^(BODY|HEADER)\b(.*)/){ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
67
|
6
|
|
|
|
|
10
|
$replacement = $self->_expand_response_param($1,$2); |
68
|
|
|
|
|
|
|
} elsif($param =~ m/^STASH($RE{balanced}{-parens => '[]'})(\/.*)?/){ |
69
|
6
|
|
|
|
|
520
|
my ($key, $dpath) = ($2, $3); |
70
|
6
|
|
|
|
|
104
|
$replacement = $self->stash(substr($key,1,-1)); |
71
|
6
|
100
|
|
|
|
17
|
if($dpath){ |
72
|
3
|
|
|
|
|
7
|
$replacement = _apply_dpath($replacement, $dpath) |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} elsif($param =~ m/^FILE($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){ |
75
|
0
|
|
|
|
|
0
|
my $file = substr($1, 1, -1); |
76
|
0
|
0
|
0
|
|
|
0
|
my $encoding = $2 ? substr($2, 1, -1) : $self->config->get('binmode') || 'utf8'; |
77
|
0
|
|
|
|
|
0
|
$replacement = read_file( $file, { binmode => ":encoding($encoding)" } ); |
78
|
|
|
|
|
|
|
} elsif($param =~ m/^PROMPT($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){ |
79
|
0
|
|
|
|
|
0
|
my($prompt,$default) = ($1, $2); |
80
|
0
|
0
|
|
|
|
0
|
$replacement = $self->term->readline( substr( $prompt, 1, -1 ) . ' ', ($default ? substr( $default, 1, -1 ) : () ) ); |
81
|
|
|
|
|
|
|
} |
82
|
12
|
100
|
|
|
|
248
|
return defined $replacement ? $replacement : $orig; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _expand_response_param { |
86
|
6
|
|
|
6
|
|
6
|
my $self = shift; |
87
|
6
|
|
|
|
|
6
|
my $section = shift; |
88
|
6
|
|
|
|
|
6
|
my $sub_section = shift; |
89
|
6
|
|
|
|
|
117
|
my $client = $self->client; |
90
|
6
|
100
|
100
|
|
|
446
|
if($section eq 'HEADER' && $sub_section =~ m/($RE{balanced}{-parens => '[]'})/){ |
|
|
100
|
|
|
|
|
|
91
|
1
|
|
|
|
|
114
|
return $client->response->header(substr($1,1,-1)); |
92
|
|
|
|
|
|
|
} elsif($section eq 'BODY'){ |
93
|
4
|
100
|
|
|
|
13
|
if(!$sub_section){ |
|
|
50
|
|
|
|
|
|
94
|
1
|
|
|
|
|
7
|
return $client->response_data; |
95
|
|
|
|
|
|
|
} elsif( $sub_section =~ m{^/} ){ |
96
|
3
|
|
|
|
|
16
|
return _apply_dpath($client->response_data, $sub_section); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
1
|
|
|
|
|
75
|
return undef; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _apply_dpath { |
103
|
6
|
|
|
6
|
|
110
|
my $data = shift; |
104
|
6
|
|
|
|
|
6
|
my $path = shift; |
105
|
6
|
|
|
|
|
729
|
require Data::DPath; |
106
|
6
|
|
|
|
|
83976
|
my $dpath = Data::DPath::Path->new(path => $path); |
107
|
6
|
|
|
|
|
579
|
my @matches = $dpath->match($data); |
108
|
6
|
100
|
|
|
|
650
|
return @matches > 1 ? \@matches : $matches[0]; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |