File: Method.pm

package info (click to toggle)
libextutils-xspp-perl 0.1800-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 996 kB
  • ctags: 1,861
  • sloc: perl: 8,324; cpp: 125; makefile: 2
file content (125 lines) | stat: -rw-r--r-- 2,648 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package ExtUtils::XSpp::Node::Method;
use strict;
use warnings;
use base 'ExtUtils::XSpp::Node::Function';

=head1 NAME

ExtUtils::XSpp::Node::Method - Node representing a method

=head1 DESCRIPTION

An L<ExtUtils::XSpp::Node::Function> sub-class representing a single method
declaration in a class such as

  class FooBar {
    int foo(double someArgument); // <-- this one
  }


=head1 METHODS

=head2 new

Creates a new C<ExtUtils::XSpp::Node::Method>.

Most of the functionality of this class is inherited. This
means that all named parameters of L<ExtUtils::XSpp::Node::Function>
are also valid for this class.

Additional named parameters accepted by the constructor:
C<class>, which can be an L<ExtUtils::XSpp::Node::Class>
object, C<const> and C<virtual> that are true if the method has
been declared C<const> or C<virtual>.

=cut

sub init {
  my $this = shift;
  my %args = @_;

  $this->SUPER::init( %args );
  $this->{CLASS} = $args{class};
  $this->{CONST} = $args{const};
  $this->{VIRTUAL} = $args{virtual};
}

=head2 perl_function_name

Returns the name of the Perl function (method) that this
method represents. It is constructed from the method's
class's name and the C<perl_name> attribute.

=cut

sub perl_function_name {
    my( $self ) = @_;

    if( $self->package_static ) {
        return $self->perl_name;
    } else {
        return $self->class->cpp_name . '::' . $self->perl_name;
    }
}

sub _call_code {
    my( $self, $arg_string ) = @_;

    return $self->_call_code_aliased($self->cpp_name, $arg_string);
}

sub _call_code_aliased {
    my( $self, $alias_name, $arg_string ) = @_;

    if( $self->package_static ) {
        return $self->class->cpp_name . '::' .
               $alias_name . '(' . $arg_string . ')';
    } else {
        return "THIS->" .
               $alias_name . '(' . $arg_string . ')';
    }
}

=head2 is_method

Returns true, since all objects of this class are methods.

=cut

sub is_method { 1 }

=head2 ACCESSORS

=head2 class

Returns the class (L<ExtUtils::XSpp::Node::Class>) that the
method belongs to.

=head2 virtual

Returns whether the method was declared virtual.

=head2 set_virtual

Set whether the method is to be considered virtual.

=head2 const

Returns whether the method was declared const.

=head2 access

Returns C<'public'>, C<'protected'> or C<'private'> depending on
method access declaration.  By default, only public methods are
generated.

=cut

sub class { $_[0]->{CLASS} }
sub virtual { $_[0]->{VIRTUAL} }
sub set_virtual { $_[0]->{VIRTUAL} = $_[1] }
sub const { $_[0]->{CONST} }
sub access { $_[0]->{ACCESS} }
sub set_access { $_[0]->{ACCESS} = $_[1] }

1;