File Coverage

blib/lib/ExtUtils/Typemaps/InputMap.pm
Criterion Covered Total %
statement 27 28 96.4
branch 10 12 83.3
condition 3 6 50.0
subroutine 7 7 100.0
pod 4 4 100.0
total 51 57 89.4


line stmt bran cond sub pod time code
1             package ExtUtils::Typemaps::InputMap;
2 15     15   335 use 5.006001;
  15         64  
3 15     15   88 use strict;
  15         33  
  15         402  
4 15     15   78 use warnings;
  15         40  
  15         5496  
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 for details.
22              
23             =head1 METHODS
24              
25             =cut
26              
27             =head2 new
28              
29             Requires C and C parameters.
30              
31             =cut
32              
33             sub new {
34 2371     2371 1 3402 my $prot = shift;
35 2371   66     5564 my $class = ref($prot)||$prot;
36 2371         4262 my %args = @_;
37              
38 2371 100       4113 if (!ref($prot)) {
39 803 50 33     2473 if (not defined $args{xstype} or not defined $args{code}) {
40 0         0 die("Need xstype and code parameters");
41             }
42             }
43              
44 2371 100       7908 my $self = bless(
45             (ref($prot) ? {%$prot} : {})
46             => $class
47             );
48              
49 2371 100       5620 $self->{xstype} = $args{xstype} if defined $args{xstype};
50 2371 100       4402 $self->{code} = $args{code} if defined $args{code};
51 2371         6127 $self->{code} =~ s/^(?=\S)/\t/mg;
52              
53 2371         5689 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 183 50   183 1 363 $_[0]->{code} = $_[1] if @_ > 1;
64 183         475 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 3186     3186 1 8160 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 53     53 1 87 my $self = shift;
86 53         129 my $code = $self->code;
87              
88 53         591 $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 53         108 $code =~ s/^\s+#/#/mg;
93 53         337 $code =~ s/\s*\z/\n/;
94              
95 53         172 return $code;
96             }
97              
98             =head1 SEE ALSO
99              
100             L
101              
102             =head1 AUTHOR
103              
104             Steffen Mueller C<>
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