line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Console; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21918
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
66
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
JavaScript::Console |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
JavaScript window.console mapping for Perl. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use JavaScript::Console; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $console = JavaScript::Console->new(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$console->group('g'); |
30
|
|
|
|
|
|
|
$console->log($v); |
31
|
|
|
|
|
|
|
$console->group_end(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
print $console->output; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 AUTHOR |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Akzhan Abdulin, C<< >> |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
1281
|
use JSON::XS (); |
|
1
|
|
|
|
|
11599
|
|
|
1
|
|
|
|
|
39
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
11
|
use constant DEFAULT_CHARSET => 'utf-8'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
838
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $json = undef; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _default_formatter { |
48
|
0
|
|
|
0
|
|
|
my $value = shift; |
49
|
0
|
|
0
|
|
|
|
$json ||= JSON::XS->new->allow_nonref->allow_blessed; |
50
|
0
|
|
|
|
|
|
return $json->encode( $value ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item B( $class, %config ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Instantiates new JavaScript::Console object with given configuration. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Available configuration options: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
* formatter - \&formatter( $value ), returns JavaScript representation for the value. |
64
|
|
|
|
|
|
|
JSON::XS-based by default. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
* charset - Charset, utf-8 by default. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
0
|
|
|
0
|
1
|
|
my ( $class, %config ) = @_; |
72
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
73
|
0
|
|
0
|
|
|
|
$config{formatter} ||= \&_default_formatter; |
74
|
0
|
|
0
|
|
|
|
$config{charset} ||= DEFAULT_CHARSET; |
75
|
0
|
|
|
|
|
|
$config{output} = []; |
76
|
0
|
|
|
|
|
|
return bless { |
77
|
|
|
|
|
|
|
%config |
78
|
|
|
|
|
|
|
}, $class; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _console_raw { |
82
|
0
|
|
|
0
|
|
|
my ( $self, $name, @args ) = @_; |
83
|
0
|
|
|
|
|
|
push @{ $self->{output} }, "console.$name(". join( ',', @args ). ");"; |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _jarg { |
88
|
0
|
|
|
0
|
|
|
my ( $self, $value ) = @_; |
89
|
0
|
|
|
|
|
|
return $self->{formatter}->( $value ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _console { |
93
|
0
|
|
|
0
|
|
|
my ( $self, $name, @args ) = @_; |
94
|
0
|
|
|
|
|
|
return $self->_console_raw( $name, map { $self->_jarg($_) } @args ); |
|
0
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item B( $self, $charset ) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Gets or sets charset. See L for details. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub charset { |
104
|
0
|
|
|
0
|
1
|
|
my ( $self, $charset ) = @_; |
105
|
0
|
0
|
|
|
|
|
return $self->{charset} unless defined( $charset ); |
106
|
0
|
|
|
|
|
|
$self->{charset} = $charset; |
107
|
0
|
|
|
|
|
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item B |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Gets resulting HTML (with script tag if not empty). |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub output { |
117
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
return '' if scalar( $self->{output} ) eq 0; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return '' |
122
|
|
|
|
|
|
|
. "" |
126
|
|
|
|
|
|
|
; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item B( $self, @args ) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Prints log message with given @args to JavaScript console. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub log { |
136
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
137
|
0
|
|
|
|
|
|
return $self->_console( 'log', @_ ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item B( $self, @args ) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Alias for L( @args ). |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub debug { |
147
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
148
|
0
|
|
|
|
|
|
return $self->log( @_ ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B( $self, @args ) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Prints info message with given @args to JavaScript console. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub info { |
158
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
159
|
0
|
|
|
|
|
|
return $self->_console( 'info', @_ ); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item B( $self, @args ) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Prints warn message with given @args to JavaScript console. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub warn { |
169
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
return $self->_console( 'warn', @_ ); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item B( $self, @args ) |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Prints error message with given @args to JavaScript console. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub error { |
180
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
181
|
0
|
|
|
|
|
|
return $self->_console( 'error', @_ ); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item B( $self, @args ) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Groups next messages in JavaScript console until L. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See also L. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub group { |
193
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
194
|
0
|
|
|
|
|
|
return $self->_console('group', @_); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item B( $self, @args ) |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Groups and collapses by default next messages in JavaScript console until L. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
See also L. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub group_collapsed { |
206
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
207
|
0
|
|
|
|
|
|
return $self->_console('groupCollapsed', @_); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item B( $self, @args ) |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Closes previously opened group of messages in JavaScript console. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
See also L and L. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub group_end { |
219
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
220
|
0
|
|
|
|
|
|
return $self->_console('groupEnd', @_); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item B( $self, @args ) |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Low level method to inspect the HTML element. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub dir { |
230
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
231
|
0
|
|
|
|
|
|
return $self->_console_raw( 'dir', @_ ); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item B( $self, $id ) |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Inspect the HTML element with specified ID. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub dir_by_id { |
241
|
0
|
|
|
0
|
1
|
|
my ( $self, $id ) = @_; |
242
|
0
|
|
|
|
|
|
return $self->dir( "document.getElementById(". _default_formatter($id). ")" ); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=back |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 BUGS |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
250
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
251
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 SUPPORT |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
perldoc JavaScript::Console |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
You can also look for information at: |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=over 4 |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
L |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * CPAN Ratings |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
L |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * Search CPAN |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
L |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=back |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Copyright 2012 Akzhan Abdulin. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
288
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
289
|
|
|
|
|
|
|
copy of the full license at: |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
294
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
295
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
296
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
299
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
300
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
303
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
306
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
307
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
308
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
309
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
310
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
311
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
312
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
315
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
316
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
317
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
318
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
319
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
320
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
321
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
1; # End of JavaScript::Console |