xref: /openbsd-src/gnu/usr.bin/perl/dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps/InputMap.pm (revision e068048151d29f2562a32185e21a8ba885482260)
1package ExtUtils::Typemaps::InputMap;
2use 5.006001;
3use strict;
4use warnings;
5our $VERSION = '3.51';
6
7=head1 NAME
8
9ExtUtils::Typemaps::InputMap - Entry in the INPUT section of a typemap
10
11=head1 SYNOPSIS
12
13  use ExtUtils::Typemaps;
14  ...
15  my $input = $typemap->get_input_map('T_NV');
16  my $code = $input->code();
17  $input->code("...");
18
19=head1 DESCRIPTION
20
21Refer to L<ExtUtils::Typemaps> for details.
22
23=head1 METHODS
24
25=cut
26
27=head2 new
28
29Requires C<xstype> and C<code> parameters.
30
31=cut
32
33sub new {
34  my $prot = shift;
35  my $class = ref($prot)||$prot;
36  my %args = @_;
37
38  if (!ref($prot)) {
39    if (not defined $args{xstype} or not defined $args{code}) {
40      die("Need xstype and code parameters");
41    }
42  }
43
44  my $self = bless(
45    (ref($prot) ? {%$prot} : {})
46    => $class
47  );
48
49  $self->{xstype} = $args{xstype} if defined $args{xstype};
50  $self->{code} = $args{code} if defined $args{code};
51  $self->{code} =~ s/^(?=\S)/\t/mg;
52
53  return $self;
54}
55
56=head2 code
57
58Returns or sets the INPUT mapping code for this entry.
59
60=cut
61
62sub code {
63  $_[0]->{code} = $_[1] if @_ > 1;
64  return $_[0]->{code};
65}
66
67=head2 xstype
68
69Returns the name of the XS type of the INPUT map.
70
71=cut
72
73sub xstype {
74  return $_[0]->{xstype};
75}
76
77=head2 cleaned_code
78
79Returns a cleaned-up copy of the code to which certain transformations
80have been applied to make it more ANSI compliant.
81
82=cut
83
84sub cleaned_code {
85  my $self = shift;
86  my $code = $self->code;
87
88  $code =~ s/(?:;+\s*|;*\s+)\z//s;
89
90  # Move C pre-processor instructions to column 1 to be strictly ANSI
91  # conformant. Some pre-processors are fussy about this.
92  $code =~ s/^\s+#/#/mg;
93  $code =~ s/\s*\z/\n/;
94
95  return $code;
96}
97
98=head1 SEE ALSO
99
100L<ExtUtils::Typemaps>
101
102=head1 AUTHOR
103
104Steffen Mueller C<<smueller@cpan.org>>
105
106=head1 COPYRIGHT & LICENSE
107
108Copyright 2009, 2010, 2011, 2012 Steffen Mueller
109
110This program is free software; you can redistribute it and/or
111modify it under the same terms as Perl itself.
112
113=cut
114
1151;
116
117