line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Writer::Function; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
653
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
198
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'Class::Accessor::Fast'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
993
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ name body ]); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8781
|
use overload '""' => \&as_string; |
|
1
|
|
|
|
|
1453
|
|
|
1
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
825
|
use JavaScript::Writer::Block; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $self = bless {}, $class; |
20
|
|
|
|
|
|
|
if (ref($_[0]) eq 'CODE') { |
21
|
|
|
|
|
|
|
$self->body($_[0]); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
|
|
|
|
|
|
my %args = @_; |
25
|
|
|
|
|
|
|
while ( my ($k, $v) = each %args) { |
26
|
|
|
|
|
|
|
$self->$k($v); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub arguments { |
34
|
|
|
|
|
|
|
my ($self, @args) = @_; |
35
|
|
|
|
|
|
|
if (@args) { |
36
|
|
|
|
|
|
|
$self->{arguments} = \@args; |
37
|
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
return @{$self->{arguments}||[]} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub as_string { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
my $sub = $self->body; |
45
|
|
|
|
|
|
|
my $function_body = JavaScript::Writer::Block->new; |
46
|
|
|
|
|
|
|
$function_body->body($self->body); |
47
|
|
|
|
|
|
|
my $name = $self->name ? " $self->{name}" : ""; |
48
|
|
|
|
|
|
|
my $args = join(",", $self->arguments); |
49
|
|
|
|
|
|
|
return "function${name}($args)${function_body}"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |