use strict;
use warnings;
our $VERSION = '1.00';
-use Carp qw(croak);
+#use Carp qw(croak);
require ExtUtils::ParseXS;
require ExtUtils::ParseXS::Constants;
my %args = @_;
if (defined $args{file} and defined $args{string}) {
- croak("Cannot handle both 'file' and 'string' arguments to constructor");
+ die("Cannot handle both 'file' and 'string' arguments to constructor");
}
my $self = bless {
else {
%args = @_;
my $ctype = $args{ctype};
- croak("Need ctype argument") if not defined $ctype;
+ die("Need ctype argument") if not defined $ctype;
my $xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
$type = ExtUtils::Typemaps::Type->new(
xstype => $xstype,
}
if ($args{skip} and $args{replace}) {
- croak("Cannot use both 'skip' and 'replace'");
+ die("Cannot use both 'skip' and 'replace'");
}
if ($args{replace}) {
else {
%args = @_;
my $xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
my $code = $args{code};
- croak("Need code argument") if not defined $code;
+ die("Need code argument") if not defined $code;
$input = ExtUtils::Typemaps::InputMap->new(
xstype => $xstype,
}
if ($args{skip} and $args{replace}) {
- croak("Cannot use both 'skip' and 'replace'");
+ die("Cannot use both 'skip' and 'replace'");
}
if ($args{replace}) {
else {
%args = @_;
my $xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
my $code = $args{code};
- croak("Need code argument") if not defined $code;
+ die("Need code argument") if not defined $code;
$output = ExtUtils::Typemaps::OutputMap->new(
xstype => $xstype,
}
if ($args{skip} and $args{replace}) {
- croak("Cannot use both 'skip' and 'replace'");
+ die("Cannot use both 'skip' and 'replace'");
}
if ($args{replace}) {
sub add_string {
my $self = shift;
my %args = @_;
- croak("Need 'string' argument") if not defined $args{string};
+ die("Need 'string' argument") if not defined $args{string};
# no, this is not elegant.
my $other = ExtUtils::Typemaps->new(string => $args{string});
if (@_ > 1) {
my %args = @_;
$ctype = $args{ctype};
- croak("Need ctype argument") if not defined $ctype;
+ die("Need ctype argument") if not defined $ctype;
$ctype = _tidy_type($ctype);
}
else {
if (@_ > 1) {
my %args = @_;
$xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
}
else {
$xstype = $_[0]->xstype;
if (@_ > 1) {
my %args = @_;
$xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
}
else {
$xstype = $_[0]->xstype;
my $self = shift;
my %args = @_;
my $ctype = $args{ctype};
- croak("Need ctype argument") if not defined $ctype;
+ die("Need ctype argument") if not defined $ctype;
$ctype = _tidy_type($ctype);
my $index = $self->{typemap_lookup}{$ctype};
my $self = shift;
my %args = @_;
my $xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
my $index = $self->{input_lookup}{$xstype};
return() if not defined $index;
my $self = shift;
my %args = @_;
my $xstype = $args{xstype};
- croak("Need xstype argument") if not defined $xstype;
+ die("Need xstype argument") if not defined $xstype;
my $index = $self->{output_lookup}{$xstype};
return() if not defined $index;
my $self = shift;
my %args = @_;
my $file = defined $args{file} ? $args{file} : $self->file();
- croak("write() needs a file argument (or set the file name of the typemap using the 'file' method)")
+ die("write() needs a file argument (or set the file name of the typemap using the 'file' method)")
if not defined $file;
open my $fh, '>', $file
my %args = @_;
if (exists $args{typemap} and exists $args{file}) {
- croak("Need {file} OR {typemap} argument. Not both!");
+ die("Need {file} OR {typemap} argument. Not both!");
}
elsif (not exists $args{typemap} and not exists $args{file}) {
- croak("Need {file} or {typemap} argument!");
- }
-
- my $typemap = $args{typemap};
- if (not defined $typemap) {
- $typemap = ref($self)->new(file => $args{file});
+ die("Need {file} or {typemap} argument!");
}
my @params;
push @params, 'replace' => $args{replace} if exists $args{replace};
push @params, 'skip' => $args{skip} if exists $args{skip};
+ my $typemap = $args{typemap};
+ if (not defined $typemap) {
+ $typemap = ref($self)->new(file => $args{file}, @params);
+ }
+
# FIXME breaking encapsulation. Add accessor code.
foreach my $entry (@{$typemap->{typemap_section}}) {
$self->add_typemap( $entry, @params );
if ( exists $args{ctype}
and exists $self->{typemap_lookup}{_tidy_type($args{ctype})} )
{
- croak("Multiple definition of ctype '$args{ctype}' in TYPEMAP section");
+ die("Multiple definition of ctype '$args{ctype}' in TYPEMAP section");
}
if ( exists $args{inputmap_xstype}
and exists $self->{input_lookup}{$args{inputmap_xstype}} )
{
- croak("Multiple definition of xstype '$args{inputmap_xstype}' in INPUTMAP section");
+ die("Multiple definition of xstype '$args{inputmap_xstype}' in INPUTMAP section");
}
if ( exists $args{outputmap_xstype}
and exists $self->{output_lookup}{$args{outputmap_xstype}} )
{
- croak("Multiple definition of xstype '$args{outputmap_xstype}' in OUTPUTMAP section");
+ die("Multiple definition of xstype '$args{outputmap_xstype}' in OUTPUTMAP section");
}
return 1;
my $filename = shift;
$filename = '<string>' if not defined $filename;
+ my $replace = $self->{replace};
+ my $skip = $self->{skip};
+ die "Can only replace OR skip" if $replace and $skip;
+ my @add_params;
+ push @add_params, replace => 1 if $replace;
+ push @add_params, skip => 1 if $skip;
+
# TODO comments should round-trip, currently ignoring
# TODO order of sections, multiple sections of same type
# Heavily influenced by ExtUtils::ParseXS
$self->add_typemap(
ExtUtils::Typemaps::Type->new(
xstype => $kind, proto => $proto, ctype => $type
- )
+ ),
+ @add_params
);
} elsif (/^\s/) {
s/\s+$//;
} # end while lines
foreach my $inexpr (@input_expr) {
- $self->add_inputmap( ExtUtils::Typemaps::InputMap->new(%$inexpr) );
+ $self->add_inputmap( ExtUtils::Typemaps::InputMap->new(%$inexpr), @add_params );
}
foreach my $outexpr (@output_expr) {
- $self->add_outputmap( ExtUtils::Typemaps::OutputMap->new(%$outexpr) );
+ $self->add_outputmap( ExtUtils::Typemaps::OutputMap->new(%$outexpr), @add_params );
}
return 1;