Code/Element.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 68.7% 11 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 80.5% 58 / 72 CC 11 SCAR 15.2
CC
11
Cov
83%
exists_in_parent
8.1
is_valid_name
3.5
get_indenting
2.3
CRAP 4.6
« Code/Block.pm ↑ Summary Code.pm »
1 package JavaScript::Code::Element;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw[ $VERSION @RESERVEDWORDS ];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw[ JavaScript::Code::Accessor Clone ];
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 $VERSION = '0.08';
8
9 2 @RESERVEDWORDS = qw [
10 abstract boolean break byte
11 case catch char class const continue
12 default delete do double
13 else export extends
14 false final finally float for function
15 goto
16 if implements in instanceof int
17 long
18 native new null
19 package private protected public
20 return
21 short static super switch synchronized
22 this thow throws transient true try typeof
23 var void
24 while with
25 ];
26
27 use overload
28 0 ▶ 'eq' => sub { 0 },
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 ▶ '==' => sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=0.2
30
31 2 __PACKAGE__->mk_accessors(qw[ parent ]);
32
33 =head1 NAME
34
35 JavaScript::Code::Element - A JavaScript Element
36
37 =head1 DESCRIPTION
38
39 Base class for javascript elements like blocks, variables, functions and so on.
40
41 =head1 METHODS
42
43 =head2 new
44
45 =head2 $self->clone( )
46
47 Clones the element.
48
49 =cut
50
51 =head2 $self->parent( )
52
53 The parent element.
54
55 =cut
56
57 =head1 SEE ALSO
58
59 L<JavaScript::Code>
60
61 =head1 AUTHOR
62
63 Sascha Kiefer, C<esskar@cpan.org>
64
65 =head1 LICENSE
66
67 This library is free software, you can redistribute it and/or modify it under
68 the same terms as Perl itself.
69
70 =cut
71
72 =head2 $self->get_indenting( )
73
74 =cut
75
76 4 ▶sub get_indenting {
Subroutine get_indenting: called CC=2 SCAR=8.1
Pod documented
77 4 my ( $self, $intend ) = @_;
78
79 4 ▶ return '' unless $intend > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $intend > 1 4 0 4
80 0 return ' ' x ( $intend - 1 );
81 }
82
83 =head2 $self->exists_in_parent( )
84
85 =cut
86
87 10 ▶sub exists_in_parent {
Subroutine exists_in_parent: called CC=8 SCAR=20.9
Pod documented
88 10 my ( $self, $obj, $parent ) = @_;
89
90 10 ▶ unless ( defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 7 3 10
91 7 $parent = $self->parent;
92 7 ▶ return 0 unless defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent 4 3 7
93
94 3 return $self->exists_in_parent( $obj, $parent );
95 }
96
97 3 ▶ if ( $parent->can('elements') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->can("elements")) 3 0 3
98 3 foreach my $element ( @{ $parent->elements } ) {
99 last
100 5 ▶ if Scalar::Util::refaddr($element) ==
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($element) == builtin::refaddr($self) 3 2 5
101 Scalar::Util::refaddr($self);
102 2 ▶ next unless $element->isa('JavaScript::Code::Variable');
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("JavaScript::Code::Variable") 0 2 2
103 2 ▶ return 1 if $obj eq $element;
Branch: 1 branch
BranchTrueFalseTotal
if $obj eq $element 0 2 2
104
105 }
106 }
107
108 3 return $parent->exists_in_parent($obj);
109 }
110
111 { # I do not like this, but well ... :-)
112
113 2 my %ReservedWords = map { ( $_, 1 ) } @RESERVEDWORDS;
114
115 =head2 $self->is_valid_name( )
116
117 =cut
118
119 4 ▶ sub is_valid_name {
Subroutine is_valid_name: called CC=3 SCAR=12.5
Pod documented
120 4 my ( $self, $name, $built_in ) = @_;
121
122 4 ▶ return 0 if !$built_in and exists $ReservedWords{$name};
Branch: 1 branch
BranchTrueFalseTotal
if not $built_in and exists $ReservedWords{$name} 0 4 4
Condition33%1/3
not $built_in and exists $ReservedWords{$name}
!ll&&!rl&&r
040
MC/DC0%0/2
not $built_in and exists $ReservedWords{$name}
not $built_in exists $ReservedWords{$name}
Truth table33%1/3
not(A) and B
A= not $built_inB= exists $ReservedWords{$name}
ABresult
0X0
100
111
123 4 return $name =~ m{^[a-zA-Z][a-zA-Z0-9_]*$};
124 }
125 }
126
127 2 1;
128
« Code/Block.pm ↑ Summary Code.pm »