line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Type;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict;
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
9
|
use vars qw[ $VERSION ];
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
73
|
|
5
|
2
|
|
|
|
|
298
|
use base qw[
|
6
|
|
|
|
|
|
|
JavaScript::Code::Accessor
|
7
|
|
|
|
|
|
|
JavaScript::Code::Value
|
8
|
2
|
|
|
2
|
|
8
|
];
|
|
2
|
|
|
|
|
3
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
11
|
use overload '""' => sub { shift->output };
|
|
2
|
|
|
0
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
|
0
|
|
|
|
|
0
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ type value ]);
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1008
|
use JavaScript::Code::String ();
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
15
|
2
|
|
|
2
|
|
1024
|
use JavaScript::Code::Number ();
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
35
|
|
16
|
2
|
|
|
2
|
|
1331
|
use JavaScript::Code::Array ();
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
39
|
|
17
|
2
|
|
|
2
|
|
1631
|
use JavaScript::Code::Hash ();
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
821
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = '0.08';
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
JavaScript::Code::Type - A JavaScript Type
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#!/usr/bin/perl
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use strict;
|
30
|
|
|
|
|
|
|
use warnings;
|
31
|
|
|
|
|
|
|
use JavaScript::Code::Type;
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $type = JavaScript::Code::Type->new({ type => 'String' })->value("Go for it!");
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print $type->output;
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 JavaScript::Code::Type->new( )
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new {
|
45
|
2
|
|
|
2
|
1
|
3
|
my $this = shift;
|
46
|
2
|
|
33
|
|
|
36
|
my $class = ref($this) || $this;
|
47
|
|
|
|
|
|
|
|
48
|
2
|
50
|
|
|
|
17
|
return $class->SUPER::new(@_)
|
49
|
|
|
|
|
|
|
unless $class eq __PACKAGE__;
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my $args = shift;
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
0
|
my $via = lc( delete $args->{type} || '' )
|
54
|
|
|
|
|
|
|
or die "No type provided.";
|
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
$via = ucfirst $via;
|
57
|
0
|
|
|
|
|
0
|
$via = "JavaScript::Code::$via";
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
eval "require $via"; # make sure, it is loaded
|
60
|
0
|
0
|
|
|
|
0
|
die $@ if $@;
|
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
return $via->new( $args, @_ );
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 $self->type( )
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns a string that represents the underlaying type.
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 $self->value( $value )
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Gets or sets the associated value.
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 $self->build( )
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub build {
|
80
|
4
|
|
|
4
|
1
|
5
|
my $this = shift;
|
81
|
4
|
|
33
|
|
|
23
|
my $class = ref($this) || $this;
|
82
|
|
|
|
|
|
|
|
83
|
4
|
50
|
50
|
|
|
26
|
my $ref = @_ ? Scalar::Util::reftype( $_[0] ) || '' : '';
|
84
|
|
|
|
|
|
|
|
85
|
4
|
50
|
|
|
|
14
|
my %args = $ref eq 'HASH' ? %{ shift() } : @_;
|
|
0
|
|
|
|
|
0
|
|
86
|
4
|
|
|
|
|
6
|
my $value = $args{value};
|
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
3
|
my $object;
|
89
|
4
|
100
|
|
|
|
9
|
if ( defined $value ) {
|
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
5
|
my $reftype = ref $value;
|
92
|
|
|
|
|
|
|
|
93
|
2
|
50
|
33
|
|
|
18
|
if ( $reftype eq 'ARRAY' ) {
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
$object = JavaScript::Code::Array->new( { value => $value } );
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
elsif ( $reftype eq 'HASH' ) {
|
97
|
0
|
|
|
|
|
0
|
$object = JavaScript::Code::Hash->new( { value => $value } );
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
elsif ( $reftype eq 'SCALAR' or $reftype eq '' ) {
|
100
|
2
|
50
|
|
|
|
7
|
$value = $reftype eq 'SCALAR' ? ${$value} : $value;
|
|
0
|
|
|
|
|
0
|
|
101
|
2
|
100
|
|
|
|
33
|
$object =
|
102
|
|
|
|
|
|
|
Scalar::Util::looks_like_number($value)
|
103
|
|
|
|
|
|
|
? JavaScript::Code::Number->new( { value => $value } )
|
104
|
|
|
|
|
|
|
: JavaScript::Code::String->new( { value => $value } );
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
elsif ( $value->isa('JavaScript::Code::Value') ) {
|
107
|
0
|
|
|
|
|
0
|
$object = $value;
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
|
110
|
2
|
50
|
|
|
|
27
|
die "Unexpected type '$reftype'." unless defined $object;
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
19
|
return $object;
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 $self->output( )
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns the javascript-code for that type.
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Sascha Kiefer, C
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 LICENSE
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
133
|
|
|
|
|
|
|
the same terms as Perl itself.
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1;
|
138
|
|
|
|
|
|
|
|