blib/lib/ExtUtils/XSpp/Node/Member.pm

filter: Statementstmt 95.1% 79 / 83 Branchbran 88.4% 23 / 26 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 87.5% 21 / 24 Podpod 78.5% 11 / 14 totaltotal 87.1% 142 / 163 CC 20 SCAR 12.3
CC
20
Cov
91%
_getter
7.0
_setter
7.0
print
3.0
CRAP 3.4
« blib/lib/ExtUtils/XSpp/Typemap/parsed.pm ↑ Summary blib/lib/ExtUtils/XSpp/Parser.pm »
1 package ExtUtils::XSpp::Node::Member;
2 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use base 'ExtUtils::XSpp::Node';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 ExtUtils::XSpp::Node::Member - Node representing a class member variable
10  
11 =head1 DESCRIPTION
12  
13 An L<ExtUtils::XSpp::Node> sub-class representing a single member
14 variable in a class such as
15  
16 class FooBar {
17 int foo; // <-- this one
18 }
19  
20 Member declarations do not produce any XS code unless they are
21 decorated by either C<%get> or C<%set>.
22  
23 =head1 METHODS
24  
25 =head2 new
26  
27 Creates a new C<ExtUtils::XSpp::Node::Member>.
28  
29 Named parameters: C<cpp_name> indicating the C++ name of the member,
30 C<perl_name> indicating the Perl name of the member (defaults to the
31 same as C<cpp_name>), C<type> indicates the (C++) type of the member
32 and finally C<class>, which is an L<ExtUtils::XSpp::Node::Class>.
33  
34 =cut
35  
36 12 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod documented
37 12 my $this = shift;
38 12 my %args = @_;
39  
40 12 $this->{CPP_NAME} = $args{cpp_name};
41 12 ▶ $this->{PERL_NAME} = $args{perl_name} || $args{cpp_name};
Condition33%1/3
$args{'perl_name'} || $args{'cpp_name'}
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{'perl_name'} || $args{'cpp_name'}
$args{'perl_name'} $args{'cpp_name'}
Truth table33%1/3
A || B
A= $args{'perl_name'}B= $args{'cpp_name'}
ABresult
1X1
011
000
42 12 $this->{TYPE} = $args{type};
43 12 $this->{CLASS} = $args{class};
44 12 $this->{CONDITION} = $args{condition};
45 12 $this->{TAGS} = $args{tags};
46 12 $this->{EMIT_CONDITION} = $args{emit_condition};
47 }
48  
49 12 ▶sub print {
Subroutine print: called CC=3 SCAR=11.0
Pod documented
50 12 my( $this, $state ) = @_;
51 12 my $str = '';
52  
53 12 ▶ $str .= $this->_getter->print( $state ) if $this->_getter;
Branch: 1 branch
BranchTrueFalseTotal
if $this->_getter 9 3 12
54 12 ▶ $str .= $this->_setter->print( $state ) if $this->_setter;
Branch: 1 branch
BranchTrueFalseTotal
if $this->_setter 9 3 12
55  
56 12 return $str;
57 }
58  
59 21 ▶sub _getter {
Subroutine _getter: called CC=7 SCAR=19.5
60 21 my( $this ) = @_;
61  
62 21 ▶ die 'Tried to create getter before adding member to a class'
Branch: 1 branch
BranchTrueFalseTotal
unless $this->class 0 21 21
63 unless $this->class;
64 21 ▶ return $this->{_getter} if $this->{_getter};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"_getter"} 9 12 21
65  
66 # TODO use plugin infrastructure
67 12 my $getter;
68 12 for my $tag ( @{$this->tags} ) {
69 10 ▶ if( $tag->{any} eq 'get' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"any"} eq "get") 9 1 10
70 9 ▶ $getter = $tag->{positional}[0] || '';
Condition100%2/2
$tag->{'positional'}[0] || ''
l!l
18
MC/DC100%1/1
$tag->{'positional'}[0] || ''
$tag->{'positional'}[0]
Truth table100%2/2
A
A= $tag->{'positional'}[0]
Aresult
11
00
71 9 last;
72 }
73 }
74 12 ▶ return unless defined $getter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $getter 3 9 12
75  
76 my $f = $this->{_getter} =
77 9 ExtUtils::XSpp::Node::Method->new
78 ( class => $this->class,
79 cpp_name => $this->_getter_name( $getter ),
80 ret_type => $this->type,
81 call_code => $this->_getter_code,
82 condition => $this->condition,
83 emit_condition => $this->emit_condition,
84 const => 1,
85 );
86 9 $f->set_ret_typemap( $this->typemap );
87 9 $f->resolve_typemaps;
88 9 $f->disable_exceptions;
89  
90 9 return $this->{_getter};
91 }
92  
93 21 ▶sub _setter {
Subroutine _setter: called CC=7 SCAR=19.5
94 21 my( $this ) = @_;
95  
96 21 ▶ die 'Tried to create getter before adding member to a class'
Branch: 1 branch
BranchTrueFalseTotal
unless $this->class 0 21 21
97 unless $this->class;
98 21 ▶ return $this->{_setter} if $this->{_setter};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"_setter"} 9 12 21
99  
100 # TODO use plugin infrastructure
101 12 my $setter;
102 12 for my $tag ( @{$this->tags} ) {
103 18 ▶ if( $tag->{any} eq 'set' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"any"} eq "set") 9 9 18
104 9 ▶ $setter = $tag->{positional}[0] || '';
Condition100%2/2
$tag->{'positional'}[0] || ''
l!l
18
MC/DC100%1/1
$tag->{'positional'}[0] || ''
$tag->{'positional'}[0]
Truth table100%2/2
A
A= $tag->{'positional'}[0]
Aresult
11
00
105 9 last;
106 }
107 }
108 12 ▶ return unless defined $setter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $setter 3 9 12
109  
110 my $f = $this->{_setter} =
111 9 ExtUtils::XSpp::Node::Method->new
112 ( class => $this->class,
113 cpp_name => $this->_setter_name( $setter ),
114 arguments => [ ExtUtils::XSpp::Node::Argument->new
115 ( type => $this->type,
116 name => 'value'
117 )
118 ],
119 ret_type => ExtUtils::XSpp::Node::Type->new( base => 'void' ),
120 call_code => $this->_setter_code,
121 condition => $this->condition,
122 emit_condition => $this->emit_condition,
123 );
124 9 $f->set_arg_typemap( 0, $this->typemap );
125 9 $f->resolve_typemaps;
126 9 $f->disable_exceptions;
127  
128 9 return $this->{_setter};
129 }
130  
131 9 ▶sub _getter_code {
Subroutine _getter_code: called CC=1 SCAR=0.0
132 9 my( $this ) = @_;
133  
134 9 return [ sprintf 'RETVAL = THIS->%s', $this->cpp_name ];
135 }
136  
137 9 ▶sub _getter_name {
Subroutine _getter_name: called CC=2 SCAR=6.9
138 9 my( $this, $name ) = @_;
139  
140 9 ▶ return $name if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 1 8 9
141 8 return $this->class->_getter_name( $this->perl_name );
142 }
143  
144 9 ▶sub _setter_code {
Subroutine _setter_code: called CC=1 SCAR=0.0
145 9 my( $this ) = @_;
146  
147 9 return [ sprintf 'THIS->%s = value', $this->cpp_name ];
148 }
149  
150 9 ▶sub _setter_name {
Subroutine _setter_name: called CC=2 SCAR=6.9
151 9 my( $this, $name ) = @_;
152  
153 9 ▶ return $name if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 1 8 9
154 8 return $this->class->_setter_name( $this->perl_name );
155 }
156  
157 =head2 resolve_typemaps
158  
159 Fetches the L<ExtUtils::XSpp::Typemap> object for the type
160 from the typemap registry and stores a reference to the object.
161  
162 =cut
163  
164 12 ▶sub resolve_typemaps {
Subroutine resolve_typemaps: called CC=2 SCAR=8.1
Pod documented
165 12 my $this = shift;
166  
167 $this->{TYPEMAPS}{TYPE} ||=
168 12 ▶ ExtUtils::XSpp::Typemap::get_typemap_for_type( $this->type );
Condition33%1/3
$this->{"TYPEMAPS"}{"TYPE"} ||= ExtUtils::XSpp::Typemap::get_typemap_for_type($this->type)
l!l&&r!l&&!r
0120
MC/DC0%0/2
$this->{"TYPEMAPS"}{"TYPE"} ||= ExtUtils::XSpp::Typemap::get_typemap_for_type($this->type)
$this->{"TYPEMAPS"}{"TYPE"} ExtUtils::XSpp::Typemap::get_typemap_for_type($this->type)
Truth table33%1/3
A ||= B
A= $this->{"TYPEMAPS"}{"TYPE"}B= ExtUtils::XSpp::Typemap::get_typemap_for_type($this->type)
ABresult
1X1
011
000
169 }
170  
171 =head1 ACCESSORS
172  
173 =head2 cpp_name
174  
175 Returns the C++ name of the member.
176  
177 =head2 perl_name
178  
179 Returns the Perl name of the member (defaults to same as C++).
180  
181 =head2 set_perl_name
182  
183 Sets the Perl name of the member.
184  
185 =head2 type
186  
187 Returns the C++ type for the member.
188  
189 =head2 class
190  
191 Returns the class (L<ExtUtils::XSpp::Node::Class>) that the
192 member belongs to.
193  
194 =head2 access
195  
196 Returns C<'public'>, C<'protected'> or C<'private'> depending on
197 member access declaration.
198  
199 =cut
200  
201 18 ▶sub cpp_name { $_[0]->{CPP_NAME} }
Subroutine cpp_name: called CC=1 SCAR=0.0
Pod documented
202 0 ▶sub set_cpp_name { $_[0]->{CPP_NAME} = $_[1] }
Subroutine set_cpp_name: not called CC=1 SCAR=6.9
Pod undocumented
203 16 ▶sub perl_name { $_[0]->{PERL_NAME} }
Subroutine perl_name: called CC=1 SCAR=0.0
Pod documented
204 7 ▶sub set_perl_name { $_[0]->{PERL_NAME} = $_[1] }
Subroutine set_perl_name: called CC=1 SCAR=0.0
Pod documented
205 30 ▶sub type { $_[0]->{TYPE} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
206 24 ▶sub tags { $_[0]->{TAGS} }
Subroutine tags: called CC=1 SCAR=0.0
Pod undocumented
207 76 ▶sub class { $_[0]->{CLASS} }
Subroutine class: called CC=1 SCAR=0.0
Pod documented
208 12 ▶sub access { $_[0]->{ACCESS} }
Subroutine access: called CC=1 SCAR=0.0
Pod documented
209 0 ▶sub set_access { $_[0]->{ACCESS} = $_[1] }
Subroutine set_access: not called CC=1 SCAR=6.9
Pod undocumented
210  
211 =head2 typemap
212  
213 Returns the typemap for member type.
214  
215 =head2 set_typemap( typemap )
216  
217 Sets the typemap for member type.
218  
219 =cut
220  
221 18 ▶sub typemap {
Subroutine typemap: called CC=2 SCAR=7.1
Pod documented
222 18 my ($this) = @_;
223  
224 18 ▶ die "Typemap not available yet" unless $this->{TYPEMAPS}{TYPE};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"TYPEMAPS"}{"TYPE"} 0 18 18
225 18 return $this->{TYPEMAPS}{TYPE};
226 }
227  
228 0 ▶sub set_typemap {
Subroutine set_typemap: not called CC=1 SCAR=6.9
Pod documented
229 0 my ($this, $typemap) = @_;
230  
231 0 $this->{TYPEMAPS}{TYPE} = $typemap;
232 }
233  
234 21 1;
« blib/lib/ExtUtils/XSpp/Typemap/parsed.pm ↑ Summary blib/lib/ExtUtils/XSpp/Parser.pm »