| 1 | package ExtUtils::XSpp::Node::Constructor; | ||||||||||
| 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 base 'ExtUtils::XSpp::Node::Method'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | ExtUtils::XSpp::Node::Constructor - Node representing a constructor method | ||||||||||
| 9 | |||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||
| 11 | |||||||||||
| 12 | An L<ExtUtils::XSpp::Node::Method> subclass representing a | ||||||||||
| 13 | constructor such as: | ||||||||||
| 14 | |||||||||||
| 15 | class FooBar { | ||||||||||
| 16 | FooBar(); // <-- this one | ||||||||||
| 17 | }; | ||||||||||
| 18 | |||||||||||
| 19 | =head1 METHODS | ||||||||||
| 20 | |||||||||||
| 21 | =head2 new | ||||||||||
| 22 | |||||||||||
| 23 | Creates a new C<ExtUtils::XSpp::Node::Constructor>. | ||||||||||
| 24 | |||||||||||
| 25 | Most of the functionality of this class is inherited. This | ||||||||||
| 26 | means that all named parameters of L<ExtUtils::XSpp::Node::Method> | ||||||||||
| 27 | and its base class are also valid for this class' constructor. | ||||||||||
| 28 | |||||||||||
| 29 | Additionally, this class requires that no return type has | ||||||||||
| 30 | been specified as constructors do not have return types. | ||||||||||
| 31 | |||||||||||
| 32 | =cut | ||||||||||
| 33 | |||||||||||
| 34 | 4 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 35 | 4 | my $this = shift; | |||||||||
| 36 | 4 | $this->SUPER::init( @_ ); | |||||||||
| 37 | |||||||||||
| 38 | 4 | ▶ | die "Can't specify return value in constructor" if $this->{RET_TYPE}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 4 | ▶ | sub print { | ||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | 4 | my $this = shift; | |||||||||
| 43 | 4 | my $state = shift; | |||||||||
| 44 | 4 | my $out = $this->SUPER::print( $state ); | |||||||||
| 45 | |||||||||||
| 46 | 4 | return sprintf <<EOT, $out; | |||||||||
| 47 | #undef xsp_constructor_class | ||||||||||
| 48 | #define xsp_constructor_class(c) (CLASS) | ||||||||||
| 49 | |||||||||||
| 50 | %s#undef xsp_constructor_class | ||||||||||
| 51 | #define xsp_constructor_class(c) (c) | ||||||||||
| 52 | |||||||||||
| 53 | EOT | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | =head2 ret_type | ||||||||||
| 57 | |||||||||||
| 58 | Unlike the C<ret_type> method of the L<ExtUtils::XSpp::Node::Method> class, | ||||||||||
| 59 | C<ret_type> will return the type "pointer to object of this class" | ||||||||||
| 60 | as return type of the constructor. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 12 | ▶ | sub ret_type { | ||||||||
|
Subroutine
ret_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | 12 | my $this = shift; | |||||||||
| 66 | |||||||||||
| 67 | 12 | ExtUtils::XSpp::Node::Type->new( base => $this->class->cpp_name, | |||||||||
| 68 | pointer => 1 ); | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 4 | ▶ | sub perl_function_name { | ||||||||
|
Subroutine
perl_function_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 72 | 4 | my $this = shift; | |||||||||
| 73 | 4 | my( $pname, $cname, $pclass, $cclass ) = ( $this->perl_name, | |||||||||
| 74 | $this->cpp_name, | ||||||||||
| 75 | $this->class->perl_name, | ||||||||||
| 76 | $this->class->cpp_name ); | ||||||||||
| 77 | |||||||||||
| 78 | 4 | ▶ | if( $pname ne $cname ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 3 | return $cclass . '::' . $pname; | |||||||||
| 80 | } else { | ||||||||||
| 81 | 1 | return $cclass . '::' . 'new'; | |||||||||
| 82 | } | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 4 | ▶ | sub _call_code { return "new " . $_[0]->class->cpp_name . | ||||||||
|
Subroutine
_call_code: called CC=1 SCAR=0.0
| |||||||||||
| 86 | '(' . $_[1] . ')'; } | ||||||||||
| 87 | |||||||||||
| 88 | 21 | 1; | |||||||||