line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
77203
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
2
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Net::NodeTransformator; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: interface to node transformator |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2126
|
use AnyEvent; |
|
2
|
|
|
|
|
8379
|
|
|
2
|
|
|
|
|
56
|
|
9
|
2
|
|
|
2
|
|
2073
|
use AnyEvent::Handle; |
|
2
|
|
|
|
|
32429
|
|
|
2
|
|
|
|
|
67
|
|
10
|
2
|
|
|
2
|
|
1312
|
use AnyEvent::Socket; |
|
2
|
|
|
|
|
30843
|
|
|
2
|
|
|
|
|
302
|
|
11
|
2
|
|
|
2
|
|
1486
|
use AnyEvent::Proc 0.101; |
|
2
|
|
|
|
|
96622
|
|
|
2
|
|
|
|
|
107
|
|
12
|
2
|
|
|
2
|
|
16
|
use Try::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
111
|
|
13
|
2
|
|
|
2
|
|
516
|
use Env::Path; |
|
2
|
|
|
|
|
1972
|
|
|
2
|
|
|
|
|
15
|
|
14
|
2
|
|
|
2
|
|
1758
|
use File::Temp qw(tempdir); |
|
2
|
|
|
|
|
38745
|
|
|
2
|
|
|
|
|
163
|
|
15
|
2
|
|
|
2
|
|
34
|
use POSIX qw(getcwd); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
16
|
2
|
|
|
2
|
|
2439
|
use CBOR::XS (); |
|
2
|
|
|
|
|
8738
|
|
|
2
|
|
|
|
|
68
|
|
17
|
2
|
|
|
2
|
|
21
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2487
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.104'; # VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
1
|
|
my ( $class, $hostport ) = @_; |
23
|
0
|
0
|
|
|
|
|
if ( $hostport !~ m{:} ) { |
24
|
0
|
0
|
|
|
|
|
if ( $hostport =~ m{^\d+$} ) { |
25
|
0
|
|
|
|
|
|
$hostport = "localhost:$hostport"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
0
|
|
|
|
|
|
$hostport = "unix/:$hostport"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
my ( $host, $port ) = parse_hostport($hostport); |
32
|
0
|
0
|
0
|
|
|
|
if ( $host eq 'unix/' and $port !~ m{^/} ) { |
33
|
0
|
|
|
|
|
|
$port = getcwd . '/' . $port; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
bless { |
36
|
0
|
|
0
|
|
|
|
host => $host, |
37
|
|
|
|
|
|
|
port => $port, |
38
|
|
|
|
|
|
|
} => ref $class |
39
|
|
|
|
|
|
|
|| $class; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub standalone { |
43
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my %options; |
46
|
0
|
0
|
0
|
|
|
|
if ( @_ > 1 and !( @_ % 2 ) ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
%options = @_; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( @_ == 1 ) { |
50
|
0
|
|
|
|
|
|
$options{connect} = shift; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif (@_) { |
53
|
0
|
|
|
|
|
|
croak "wrong paramater given for $class->standalone"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
$options{bin} ||= 'transformator'; |
57
|
0
|
0
|
|
|
|
|
my $path = |
58
|
|
|
|
|
|
|
$options{bin} =~ m{/} |
59
|
|
|
|
|
|
|
? $options{bin} |
60
|
|
|
|
|
|
|
: ( Env::Path->PATH->Whence( $options{bin} ) )[0]; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
unless ($path) { |
63
|
0
|
|
|
|
|
|
croak "binary " . $options{bin} . " not found"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
unless ( $options{connect} ) { |
67
|
0
|
|
|
|
|
|
my $tmpdir = tempdir( CLEANUP => 1 ); |
68
|
0
|
|
|
|
|
|
$options{connect} = "$tmpdir/~sock"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $errstr = ''; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
my $cv = $options{cv} // AE::cv; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $server = AnyEvent::Proc->new( |
76
|
|
|
|
|
|
|
bin => $path, |
77
|
|
|
|
|
|
|
args => [ $options{connect} ], |
78
|
|
|
|
|
|
|
rtimeout => 10, |
79
|
|
|
|
|
|
|
errstr => \$errstr, |
80
|
|
|
|
|
|
|
on_rtimeout => sub { |
81
|
|
|
|
|
|
|
shift->fire_and_kill( |
82
|
|
|
|
|
|
|
10, |
83
|
|
|
|
|
|
|
sub { |
84
|
0
|
|
|
|
|
|
$cv->croak( 'timeout (' . $errstr . ')' ); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
0
|
|
|
); |
87
|
|
|
|
|
|
|
}, |
88
|
0
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$server->readlines_cb( |
91
|
|
|
|
|
|
|
sub { |
92
|
0
|
0
|
|
0
|
|
|
if ( shift =~ m{server bound} ) { |
93
|
0
|
|
|
|
|
|
$server->stop_rtimeout; |
94
|
0
|
|
|
|
|
|
my $client = $class->new( $options{connect} ); |
95
|
0
|
|
|
|
|
|
$client->{_server} = $server; |
96
|
0
|
|
|
|
|
|
$cv->send($client); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
0
|
|
|
|
if ( $options{cb} or $options{cv} ) { |
102
|
0
|
0
|
|
|
|
|
$cv->cb( $options{cb} ) if $options{cb}; |
103
|
0
|
|
|
|
|
|
return $cv; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
|
return $cv->recv; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub cleanup { |
111
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
112
|
0
|
0
|
|
|
|
|
if ( exists $self->{_server} ) { |
113
|
0
|
|
|
|
|
|
my $server = delete $self->{_server}; |
114
|
0
|
|
|
|
|
|
$server->fire_and_kill(10); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else { |
117
|
0
|
|
|
|
|
|
AE::log note => |
118
|
|
|
|
|
|
|
"$self->cleanup called when no standalone server active"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub transform_cv { |
124
|
0
|
|
|
0
|
1
|
|
my ( $self, %options ) = @_; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if ( $options{on_error} ) { |
127
|
0
|
|
|
|
|
|
confess |
128
|
|
|
|
|
|
|
"on_error option is deprecated. the returned condvar will now croak on receive if there is an error."; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
0
|
|
|
|
my $cv = $options{cv} || AE::cv; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $host = $self->{host}; |
134
|
0
|
|
|
|
|
|
my $port = $self->{port}; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
tcp_connect( |
137
|
|
|
|
|
|
|
$host, $port, |
138
|
|
|
|
|
|
|
sub { |
139
|
0
|
0
|
|
0
|
|
|
return $cv->croak("Connect to $host:$port failed: $!") unless @_; |
140
|
0
|
|
|
|
|
|
my ($fh) = @_; |
141
|
0
|
|
|
|
|
|
my $AEH; |
142
|
|
|
|
|
|
|
$AEH = AnyEvent::Handle->new( |
143
|
|
|
|
|
|
|
fh => $fh, |
144
|
|
|
|
|
|
|
on_error => sub { |
145
|
0
|
|
|
|
|
|
my ( $handle, $fatal, $message ) = @_; |
146
|
0
|
|
|
|
|
|
$handle->destroy; |
147
|
0
|
|
|
|
|
|
$cv->croak("Socket error: $message"); |
148
|
|
|
|
|
|
|
}, |
149
|
|
|
|
|
|
|
on_eof => sub { |
150
|
0
|
|
|
|
|
|
$AEH->destroy; |
151
|
|
|
|
|
|
|
}, |
152
|
0
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
$AEH->push_read( |
154
|
|
|
|
|
|
|
cbor => sub { |
155
|
0
|
|
|
|
|
|
my $answer = $_[1]; |
156
|
0
|
0
|
0
|
|
|
|
if ( defined $answer and ref $answer eq 'HASH' ) { |
157
|
0
|
0
|
|
|
|
|
if ( exists $answer->{error} ) { |
|
|
0
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$cv->croak( "Service error: " . $answer->{error} ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ( exists $answer->{result} ) { |
161
|
0
|
|
|
|
|
|
$cv->send( $answer->{result} ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
0
|
|
|
|
|
|
$cv->croak( |
165
|
|
|
|
|
|
|
"Something is wrong: no result and no error"); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
else { |
169
|
0
|
|
|
|
|
|
$cv->croak("No answer"); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
); |
173
|
0
|
|
0
|
|
|
|
$AEH->push_write( cbor => |
174
|
|
|
|
|
|
|
[ $options{engine}, $options{input}, $options{data} || {} ] ); |
175
|
|
|
|
|
|
|
} |
176
|
0
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
$cv->cb( $options{cb} ) if $options{cb}; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$cv; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub transform { |
184
|
0
|
|
|
0
|
1
|
|
my ( $self, $engine, $input, $data ) = @_; |
185
|
0
|
|
|
|
|
|
$self->transform_cv( |
186
|
|
|
|
|
|
|
engine => $engine, |
187
|
|
|
|
|
|
|
input => $input, |
188
|
|
|
|
|
|
|
data => $data, |
189
|
|
|
|
|
|
|
)->recv; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
0
|
1
|
|
sub jade { shift->transform( jade => @_ ) } |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
0
|
1
|
|
sub coffeescript { shift->transform( coffeescript => @_ ) } |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
0
|
1
|
|
sub minify_html { shift->transform( minify_html => @_ ) } |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
0
|
1
|
|
sub minify_css { shift->transform( minify_css => @_ ) } |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
0
|
1
|
|
sub minify_js { shift->transform( minify_js => @_ ) } |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
__END__ |