File: Package.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 (86 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download | duplicates (6)
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
package ExtUtils::XSpp::Node::Package;
use strict;
use warnings;
use base 'ExtUtils::XSpp::Node';

=head1 NAME

ExtUtils::XSpp::Node::Package - Node representing a Perl package

=head1 DESCRIPTION

An L<ExtUtils::XSpp::Node> subclass representing a Perl package and
thus acting as a container for methods (cf. sub-class
L<ExtUtils::XSpp::Node::Class>) or functions.

A literal C<ExtUtils::XSpp::Node::Package> would, for example,
be created from:

  %package{Some::Perl::Namespace}

This would be compiled to a new XS line a la

MODULE=$WhateverCurrentModule PACKAGE=Some::Perl::Namespace

=head1 METHODS

=head2 new

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

Named parameters: C<cpp_name> indicating the C++ class name
(if any), and C<perl_name> indicating the name of the Perl
package. If C<perl_name> is not specified but C<cpp_name> is,
C<perl_name> defaults to C<cpp_name>.

=cut

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

  $this->{CPP_NAME} = $args{cpp_name};
  $this->{PERL_NAME} = $args{perl_name} || $args{cpp_name};
}

=head1 ACCESSORS

=head2 cpp_name

Returns the C++ name for the package (will be used for namespaces).

=head2 perl_name

Returns the Perl name for the package.

=head2 set_perl_name

Setter for the Perl package name.

=cut

sub cpp_name { $_[0]->{CPP_NAME} }
sub perl_name { $_[0]->{PERL_NAME} }
sub set_perl_name { $_[0]->{PERL_NAME} = $_[1] }

sub print {
  my $this = shift;
  my $state = shift;
  my $out = '';
  my $pcname = $this->perl_name;

  if( !defined $state->{current_module} ) {
    die "No current module: remember to add a %module{} directive";
  }
  my $cur_module = $state->{current_module}->to_string;

  $out .= <<EOT;

$cur_module PACKAGE=$pcname

EOT

  return $out;
}

1;