Debian Codegraph @

dist/ExtUtils-ParseXS/lib/ExtUtils/Typemaps/InputMap.pm

raw
1 package ExtUtils::Typemaps::InputMap;
2 use 5.006001;
3 use strict;
4 use warnings;
5 our $VERSION = '3.51';
6
7 =head1 NAME
8
9 ExtUtils::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
21 Refer to L<ExtUtils::Typemaps> for details.
22
23 =head1 METHODS
24
25 =cut
26
27 =head2 new
28
29 Requires C<xstype> and C<code> parameters.
30
31 =cut
32
33 sub 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
58 Returns or sets the INPUT mapping code for this entry.
59
60 =cut
61
62 sub code {
63 $_[0]->{code} = $_[1] if @_ > 1;
64 return $_[0]->{code};
65 }
66
67 =head2 xstype
68
69 Returns the name of the XS type of the INPUT map.
70
71 =cut
72
73 sub xstype {
74 return $_[0]->{xstype};
75 }
76
77 =head2 cleaned_code
78
79 Returns a cleaned-up copy of the code to which certain transformations
80 have been applied to make it more ANSI compliant.
81
82 =cut
83
84 sub 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
100 L<ExtUtils::Typemaps>
101
102 =head1 AUTHOR
103
104 Steffen Mueller C<<[email protected]>>
105
106 =head1 COPYRIGHT & LICENSE
107
108 Copyright 2009, 2010, 2011, 2012 Steffen Mueller
109
110 This program is free software; you can redistribute it and/or
111 modify it under the same terms as Perl itself.
112
113 =cut
114
115 1;
116