| ExtUtils-XSpp documentation | Contained in the ExtUtils-XSpp distribution. |
ExtUtils::XSpp::Node::Argument - Node representing a method/function argument
An ExtUtils::XSpp::Node subclass representing a single function or method argument such as
int foo = 0.
which would translate to an ExtUtils::XSpp::Node::Argument which has
its type set to int, its name set to foo and its default
set to 0..
Creates a new ExtUtils::XSpp::Node::Argument.
Named parameters: type indicating the C++ argument type,
name indicating the variable name, and optionally
default indicating the default value of the argument.
Returns true if the argument uses the XS length feature, false otherwise.
Returns the same as the name method unless
the argument is of the %length(something) variant.
In that case, implementation_name returns a
munged version of the name that addresses the name mangling
done by xsubpp: XSauto_length_of_somthing.
Given a code string, replaces any occurrances of
the name of this Argument with its implementation
name. If the implementation name is the same as the name,
which is the most likely case, the code remains
completely untouched.
Returns the potentially modified code.
Returns the type of the argument.
Returns the variable name of the argument variable.
Returns the default for the function parameter if any.
Returns whether there is a default for the function parameter.
| ExtUtils-XSpp documentation | Contained in the ExtUtils-XSpp distribution. |
package ExtUtils::XSpp::Node::Argument; use strict; use warnings; use base 'ExtUtils::XSpp::Node';
sub init { my $this = shift; my %args = @_; $this->{TYPE} = $args{type}; $this->{NAME} = $args{name}; $this->{DEFAULT} = $args{default}; } sub print { my $this = shift; my $state = shift; return join( ' ', $this->type->print( $state ), $this->name, ( $this->default ? ( '=', $this->default ) : () ) ); } sub uses_length { return($_[0]->name =~ /^length\([^\)]+\)/); } sub implementation_name { my $this = shift; my $name = $this->name; if ($this->uses_length) { $name =~ /^length\(([^\)]+)\)/; return "XSauto_length_of_$1"; } return $name; } sub fix_name_in_code { my $this = shift; my $code = shift; return $code if not $this->uses_length; my $name = $this->name; my $impl = $this->implementation_name; $code =~ s/\b\Q$name\E/$impl/g; return $code; }
sub type { $_[0]->{TYPE} } sub name { $_[0]->{NAME} } sub default { $_[0]->{DEFAULT} } sub has_default { defined $_[0]->{DEFAULT} } 1;