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


ExtUtils-XSpp documentation Contained in the ExtUtils-XSpp distribution.

Index


Code Index:

NAME

Top

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

DESCRIPTION

Top

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

A literal 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

METHODS

Top

new

Creates a new ExtUtils::XSpp::Node::Package.

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

ACCESSORS

Top

cpp_name

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

perl_name

Returns the Perl name for the package.

set_perl_name

Setter for the Perl package name.


ExtUtils-XSpp documentation Contained in the ExtUtils-XSpp distribution.
package ExtUtils::XSpp::Node::Package;
use strict;
use warnings;
use base 'ExtUtils::XSpp::Node';

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

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

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;