| 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'}
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'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 54 | 12 | ▶ | $str .= $this->_setter->print( $state ) if $this->_setter; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 63 | unless $this->class; | ||||||||||||||||||||
| 64 | 21 | ▶ | return $this->{_getter} if $this->{_getter}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 70 | 9 | ▶ | $getter = $tag->{positional}[0] || ''; | ||||||||||||||||||
|
Condition100%2/2
$tag->{'positional'}[0] || ''
MC/DC100%1/1
$tag->{'positional'}[0] || ''
$tag->{'positional'}[0]
Truth table100%2/2
A
A= $tag->{'positional'}[0]
| |||||||||||||||||||||
| 71 | 9 | last; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 12 | ▶ | return unless defined $getter; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 97 | unless $this->class; | ||||||||||||||||||||
| 98 | 21 | ▶ | return $this->{_setter} if $this->{_setter}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 104 | 9 | ▶ | $setter = $tag->{positional}[0] || ''; | ||||||||||||||||||
|
Condition100%2/2
$tag->{'positional'}[0] || ''
MC/DC100%1/1
$tag->{'positional'}[0] || ''
$tag->{'positional'}[0]
Truth table100%2/2
A
A= $tag->{'positional'}[0]
| |||||||||||||||||||||
| 105 | 9 | last; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | 12 | ▶ | return unless defined $setter; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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; | |||||||||||||||||||