| 1 | package ExtUtils::XSpp::Node::Package; | ||||||||||||||||||||
| 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::Package - Node representing a Perl package | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | An L<ExtUtils::XSpp::Node> subclass representing a Perl package and | ||||||||||||||||||||
| 13 | thus acting as a container for methods (cf. sub-class | ||||||||||||||||||||
| 14 | L<ExtUtils::XSpp::Node::Class>) or functions. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | A literal C<ExtUtils::XSpp::Node::Package> would, for example, | ||||||||||||||||||||
| 17 | be created from: | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | %package{Some::Perl::Namespace} | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | This would be compiled to a new XS line a la | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | MODULE=$WhateverCurrentModule PACKAGE=Some::Perl::Namespace | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 METHODS | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head2 new | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | Creates a new C<ExtUtils::XSpp::Node::Package>. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | Named parameters: C<cpp_name> indicating the C++ class name | ||||||||||||||||||||
| 32 | (if any), and C<perl_name> indicating the name of the Perl | ||||||||||||||||||||
| 33 | package. If C<perl_name> is not specified but C<cpp_name> is, | ||||||||||||||||||||
| 34 | C<perl_name> defaults to C<cpp_name>. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 84 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 39 | 84 | my $this = shift; | |||||||||||||||||||
| 40 | 84 | my %args = @_; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 84 | $this->{CPP_NAME} = $args{cpp_name}; | |||||||||||||||||||
| 43 | 84 | ▶ | $this->{PERL_NAME} = $args{perl_name} || $args{cpp_name}; | ||||||||||||||||||
|
Condition66%2/3
$args{'perl_name'} || $args{'cpp_name'}
MC/DC0%0/2
$args{'perl_name'} || $args{'cpp_name'}
$args{'perl_name'}
$args{'cpp_name'}
Truth table66%2/3
A || B
A= $args{'perl_name'}B= $args{'cpp_name'}
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 ACCESSORS | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =head2 cpp_name | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | Returns the C++ name for the package (will be used for namespaces). | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head2 perl_name | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | Returns the Perl name for the package. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head2 set_perl_name | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Setter for the Perl package name. | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 193 | ▶ | sub cpp_name { $_[0]->{CPP_NAME} } | ||||||||||||||||||
|
Subroutine
cpp_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | 89 | ▶ | sub perl_name { $_[0]->{PERL_NAME} } | ||||||||||||||||||
|
Subroutine
perl_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | 4 | ▶ | sub set_perl_name { $_[0]->{PERL_NAME} = $_[1] } | ||||||||||||||||||
|
Subroutine
set_perl_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 80 | ▶ | sub print { | ||||||||||||||||||
|
Subroutine
print: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 67 | 80 | my $this = shift; | |||||||||||||||||||
| 68 | 80 | my $state = shift; | |||||||||||||||||||
| 69 | 80 | my $out = ''; | |||||||||||||||||||
| 70 | 80 | my $pcname = $this->perl_name; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 80 | ▶ | if( !defined $state->{current_module} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 0 | die "No current module: remember to add a %module{} directive"; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 80 | my $cur_module = $state->{current_module}->to_string; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 80 | $out .= <<EOT; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | $cur_module PACKAGE=$pcname | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | EOT | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 80 | return $out; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 21 | 1; | |||||||||||||||||||