File Coverage

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