| 1 | package ExtUtils::XSpp::Node::Argument; | ||||||||||
| 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'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | ExtUtils::XSpp::Node::Argument - Node representing a method/function argument | ||||||||||
| 9 | |||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||
| 11 | |||||||||||
| 12 | An L<ExtUtils::XSpp::Node> subclass representing a single function | ||||||||||
| 13 | or method argument such as | ||||||||||
| 14 | |||||||||||
| 15 | int foo = 0. | ||||||||||
| 16 | |||||||||||
| 17 | which would translate to an C<ExtUtils::XSpp::Node::Argument> which has | ||||||||||
| 18 | its C<type> set to C<int>, its C<name> set to C<foo> and its C<default> | ||||||||||
| 19 | set to C<0.>. | ||||||||||
| 20 | |||||||||||
| 21 | =head1 METHODS | ||||||||||
| 22 | |||||||||||
| 23 | =head2 new | ||||||||||
| 24 | |||||||||||
| 25 | Creates a new C<ExtUtils::XSpp::Node::Argument>. | ||||||||||
| 26 | |||||||||||
| 27 | Named parameters: C<type> indicating the C++ argument type, | ||||||||||
| 28 | C<name> indicating the variable name, and optionally | ||||||||||
| 29 | C<default> indicating the default value of the argument. | ||||||||||
| 30 | |||||||||||
| 31 | =head2 uses_length | ||||||||||
| 32 | |||||||||||
| 33 | Returns true if the argument uses the XS length feature, false | ||||||||||
| 34 | otherwise. | ||||||||||
| 35 | |||||||||||
| 36 | =head2 implementation_name | ||||||||||
| 37 | |||||||||||
| 38 | Returns the same as the C<name> method unless | ||||||||||
| 39 | the argument is of the C<%length(something)> variant. | ||||||||||
| 40 | In that case, C<implementation_name> returns a | ||||||||||
| 41 | munged version of the name that addresses the name mangling | ||||||||||
| 42 | done by F<xsubpp>: C<XSauto_length_of_somthing>. | ||||||||||
| 43 | |||||||||||
| 44 | =head2 fix_name_in_code | ||||||||||
| 45 | |||||||||||
| 46 | Given a code string, replaces any occurrances of | ||||||||||
| 47 | the name of this C<Argument> with its implementation | ||||||||||
| 48 | name. If the implementation name is the same as the name, | ||||||||||
| 49 | which is the most likely case, the code remains | ||||||||||
| 50 | completely untouched. | ||||||||||
| 51 | |||||||||||
| 52 | Returns the potentially modified code. | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 123 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 123 | my $this = shift; | |||||||||
| 58 | 123 | my %args = @_; | |||||||||
| 59 | |||||||||||
| 60 | 123 | $this->{TYPE} = $args{type}; | |||||||||
| 61 | 123 | $this->{NAME} = $args{name}; | |||||||||
| 62 | 123 | $this->{DEFAULT} = $args{default}; | |||||||||
| 63 | 123 | $this->{TAGS} = $args{tags}; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub print { | ||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 67 | 0 | my $this = shift; | |||||||||
| 68 | 0 | my $state = shift; | |||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | return join( ' ', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | $this->type->print( $state ), | ||||||||||
| 72 | $this->name, | ||||||||||
| 73 | ( $this->default ? | ||||||||||
| 74 | ( '=', $this->default ) : () ) ); | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 132 | ▶ | sub uses_length { | ||||||||
|
Subroutine
uses_length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 78 | 132 | return($_[0]->name =~ /^length\([^\)]+\)/); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 3 | ▶ | sub implementation_name { | ||||||||
|
Subroutine
implementation_name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 82 | 3 | my $this = shift; | |||||||||
| 83 | 3 | my $name = $this->name; | |||||||||
| 84 | 3 | ▶ | if ($this->uses_length) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 3 | $name =~ /^length\(([^\)]+)\)/; | |||||||||
| 86 | 3 | return "XSauto_length_of_$1"; | |||||||||
| 87 | } | ||||||||||
| 88 | 0 | return $name; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 6 | ▶ | sub fix_name_in_code { | ||||||||
|
Subroutine
fix_name_in_code: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 92 | 6 | my $this = shift; | |||||||||
| 93 | 6 | my $code = shift; | |||||||||
| 94 | 6 | ▶ | return $code if not $this->uses_length; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 3 | my $name = $this->name; | |||||||||
| 96 | 3 | my $impl = $this->implementation_name; | |||||||||
| 97 | 3 | $code =~ s/\b\Q$name\E/$impl/g; | |||||||||
| 98 | 3 | return $code; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | =head1 ACCESSORS | ||||||||||
| 102 | |||||||||||
| 103 | =head2 type | ||||||||||
| 104 | |||||||||||
| 105 | Returns the type of the argument. | ||||||||||
| 106 | |||||||||||
| 107 | =head2 name | ||||||||||
| 108 | |||||||||||
| 109 | Returns the variable name of the argument variable. | ||||||||||
| 110 | |||||||||||
| 111 | =head2 default | ||||||||||
| 112 | |||||||||||
| 113 | Returns the default for the function parameter if any. | ||||||||||
| 114 | |||||||||||
| 115 | =head2 has_default | ||||||||||
| 116 | |||||||||||
| 117 | Returns whether there is a default for the function parameter. | ||||||||||
| 118 | |||||||||||
| 119 | =head2 function | ||||||||||
| 120 | |||||||||||
| 121 | Returns a reference to the containing function/method. | ||||||||||
| 122 | |||||||||||
| 123 | =head2 index | ||||||||||
| 124 | |||||||||||
| 125 | Returns the 0-based index of the argument in the argument list. | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | 114 | ▶ | sub type { $_[0]->{TYPE} } | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 130 | 625 | ▶ | sub name { $_[0]->{NAME} } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 131 | 114 | ▶ | sub tags { $_[0]->{TAGS} } | ||||||||
|
Subroutine
tags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 132 | |||||||||||
| 133 | 4 | ▶ | sub default { $_[0]->{DEFAULT} } | ||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 134 | 123 | ▶ | sub has_default { defined $_[0]->{DEFAULT} } | ||||||||
|
Subroutine
has_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | |||||||||||
| 136 | 1 | ▶ | sub function { $_[0]->{FUNCTION} } | ||||||||
|
Subroutine
function: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 137 | 3 | ▶ | sub index { $_[0]->{INDEX} } | ||||||||
|
Subroutine
index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 138 | |||||||||||
| 139 | 21 | 1; | |||||||||