Builder/Args.pm

filter: Statementstmt 65.9% 31 / 47 Branchbran 100% 2 / 2 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 46.6% 7 / 15 Podpod 9.0% 1 / 11 totaltotal 55.4% 46 / 83 CC 6 SCAR 10.7
CC
6
Cov
69%
List
6.0
parent
2.0
args
2.0
CRAP 2.9
« Builder.pm ↑ Summary Builder/Data.pm »
1 package Lang::Tree::Builder::Args;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Lang::Tree::Builder::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Lang::Tree::Builder::Args - wrapper for a tree node constructor's argument list.
10  
11 =head1 SYNOPSIS
12  
13 use Lang::Tree::Builder::Args;
14 my $ra_args = Lang::Tree::Builder::Args->List([ [$classname, $argname ] ... ]);
15  
16 Used internally by C<Lang::Tree::Builder> to encapsulate argument lists,
17 a C<Lang::Tree::Builder::Args> object is a Decorator of the underlying
18 C<Lang::Tree::Builder::Class>. It forwards all method requests to that class
19 and adds an addidional C<argname()> method returning the name of the
20 argument.
21  
22 =cut
23  
24 12 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
25 12 my ($class, $arg, $argname) = @_;
26 12 bless {
27 arg => $arg,
28 argname => $argname,
29 }, $class;
30 }
31  
32 =head2 List
33  
34 my $list = Lang::Tree::Builder::Args->List(\@args);
35  
36 C<@args> is an array of array refs. Each array ref contains a string
37 typename, and optionally a string varname, for example C<['Expr', 'left']>.
38  
39 Returns a listref of C<Lang::Tree::Builder::Args> objects.
40  
41 If the argument name is omitted from the sub array component describing
42 the argument, then the last part of the class namne will be used in its place.
43  
44 Argument names will be sequentially numbered to avoid conflicts, but only
45 if necessary. For example given the following call
46  
47 my $ra_args = Lang::Tree::Builder::Args->List([
48 [qw(Foo::Expr)],
49 [qw(Foo::Expr)],
50 [qw(Foo::Expr foo)],
51 [qw(Foo::Expr foo)],
52 [qw(Foo::Expr bar)],
53 [qw(Foo::ExprList)]
54 ])
55  
56 The resulting argument names will be:
57  
58 Expr1, Expr2, foo1, foo2, bar, ExprList
59  
60 =cut
61  
62 4 ▶sub List {
Subroutine List: called CC=6 SCAR=17.9
Pod documented
63 4 my ($class, $ra_args) = @_;
64 my @classes =
65 4 map { Lang::Tree::Builder::Class->new(class => $_->[0]) } @$ra_args;
66 4 my %count;
67 my %counter;
68 my @protonames =
69 4 ▶ map { $ra_args->[$_][1] || $classes[$_]->lastpart }
Condition66%2/3
$ra_args->[$_][1] || $classes[$_]->lastpart
l!l&&r!l&&!r
660
MC/DC0%0/2
$ra_args->[$_][1] || $classes[$_]->lastpart
$ra_args->[$_][1] $classes[$_]->lastpart
Truth table66%2/3
A || B
A= $ra_args->[$_][1]B= $classes[$_]->lastpart
ABresult
1X1
011
000
70 (0 .. (scalar(@classes) - 1));
71 4 foreach my $arg (@protonames) {
72 12 ▶ $count{$arg} ||= 0;
Condition100%2/2
$count{$arg} ||= 0
l!l
39
MC/DC100%1/1
$count{$arg} ||= 0
$count{$arg}
Truth table100%2/2
A
A= $count{$arg}
Aresult
11
00
73 12 $count{$arg}++;
74 12 $counter{$arg} = 0;
75 }
76 4 my @argnames;
77 4 foreach my $arg (@protonames) {
78 push @argnames,
79 (
80 $arg
81 . (
82 $count{$arg} > 1
83 12 ▶ ? ++$counter{$arg}
Branch: 1 branch
BranchTrueFalseTotal
$count{$arg} > 1 ? : 6 6 12
84 : ''
85 )
86 );
87 }
88  
89 4 [ map { $class->_new($classes[$_], $argnames[$_]) }
90 (0 .. (scalar(@classes) - 1)) ];
91 }
92  
93 # autoload interferes with tt2
94  
95 6 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
96 6 my ($self, @args) = @_;
97 6 return $self->{arg}->name(@args);
98 }
99  
100 0 ▶sub parent {
Subroutine parent: not called CC=1 SCAR=6.9
Pod undocumented
101 0 my ($self, @args) = @_;
102 0 return $self->{arg}->parent(@args);
103 }
104  
105 0 ▶sub args {
Subroutine args: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my ($self, @args) = @_;
107 0 return $self->{arg}->args(@args);
108 }
109  
110 0 ▶sub parts {
Subroutine parts: not called CC=1 SCAR=6.9
Pod undocumented
111 0 my ($self, @args) = @_;
112 0 return $self->{arg}->parts(@args);
113 }
114  
115 0 ▶sub lastpart {
Subroutine lastpart: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my ($self, @args) = @_;
117 0 return $self->{arg}->lastpart(@args);
118 }
119  
120 0 ▶sub namespace {
Subroutine namespace: not called CC=1 SCAR=6.9
Pod undocumented
121 0 my ($self, @args) = @_;
122 0 return $self->{arg}->namespace(@args);
123 }
124  
125 0 ▶sub interface {
Subroutine interface: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my ($self, @args) = @_;
127 0 return $self->{arg}->namespace(@args);
128 }
129  
130 0 ▶sub is_scalar {
Subroutine is_scalar: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my ($self, @args) = @_;
132 0 return $self->{arg}->is_scalar(@args);
133 }
134  
135 0 ▶sub is_substantial {
Subroutine is_substantial: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my ($self, @args) = @_;
137 0 return $self->{arg}->is_substantial(@args);
138 }
139  
140 12 ▶sub argname {
Subroutine argname: called CC=1 SCAR=0.0
Pod undocumented
141 12 my ($self) = @_;
142 12 return $self->{argname};
143 }
144  
145 =head1 AUTHOR
146  
147 Bill Hails <me@billhails.net>
148  
149 =head1 SEE ALSO
150  
151 L<Lang::Tree::Builder>, L<Lang::Tree::Builder::Class>.
152  
153 =cut
154  
155 6 1;
« Builder.pm ↑ Summary Builder/Data.pm »