File Coverage

blib/lib/XS/Install/FrozenShit/Typemaps/Type.pm
Criterion Covered Total %
statement 24 25 96.0
branch 12 16 75.0
condition 3 6 50.0
subroutine 8 8 100.0
pod 5 5 100.0
total 52 60 86.6


line stmt bran cond sub pod time code
1             package
2             XS::Install::FrozenShit::Typemaps::Type;
3 1     1   18 use 5.006001;
  1         4  
4 1     1   5 use strict;
  1         2  
  1         26  
5 1     1   4 use warnings;
  1         2  
  1         451  
6             require XS::Install::FrozenShit::Typemaps;
7              
8             our $VERSION = '3.57';
9              
10             =head1 NAME
11              
12             XS::Install::FrozenShit::Typemaps::Type - Entry in the TYPEMAP section of a typemap
13              
14             =head1 SYNOPSIS
15              
16             use XS::Install::FrozenShit::Typemaps;
17             ...
18             my $type = $typemap->get_type_map('char*');
19             my $input = $typemap->get_input_map($type->xstype);
20              
21             =head1 DESCRIPTION
22              
23             Refer to L for details.
24             Object associates C with C, which is the index
25             into the in- and output mapping tables.
26              
27             =head1 METHODS
28              
29             =cut
30              
31             =head2 new
32              
33             Requires C and C parameters.
34              
35             Optionally takes C parameter. Note however that the method to
36             get/set the value is called C rather than .
37              
38             =cut
39              
40             sub new {
41 201     201 1 397 my $prot = shift;
42 201   66     599 my $class = ref($prot)||$prot;
43 201         1125 my %args = @_;
44              
45 201 100       526 if (!ref($prot)) {
46 67 50 33     279 if (not defined $args{xstype} or not defined $args{ctype}) {
47 0         0 die("Need xstype and ctype parameters");
48             }
49             }
50              
51 201 100       1373 my $self = bless(
52             (ref($prot) ? {%$prot} : {proto => ''})
53             => $class
54             );
55              
56 201 100       702 $self->{xstype} = $args{xstype} if defined $args{xstype};
57 201 100       483 $self->{ctype} = $args{ctype} if defined $args{ctype};
58 201         777 $self->{tidy_ctype} = XS::Install::FrozenShit::Typemaps::tidy_type($self->{ctype});
59 201 50       500 $self->{proto} = $args{'prototype'} if defined $args{'prototype'};
60              
61 201         671 return $self;
62             }
63              
64             =head2 proto
65              
66             Returns or sets the prototype.
67              
68             =cut
69              
70             sub proto {
71 6 50   6 1 21 $_[0]->{proto} = $_[1] if @_ > 1;
72 6         26 return $_[0]->{proto};
73             }
74              
75             =head2 xstype
76              
77             Returns the name of the XS type that this C type is associated to.
78              
79             =cut
80              
81             sub xstype {
82 8     8 1 30 return $_[0]->{xstype};
83             }
84              
85             =head2 ctype
86              
87             Returns the name of the C type as it was set on construction.
88              
89             =cut
90              
91             sub ctype {
92 134 50   134 1 607 return defined($_[0]->{ctype}) ? $_[0]->{ctype} : $_[0]->{tidy_ctype};
93             }
94              
95             =head2 tidy_ctype
96              
97             Returns the canonicalized name of the C type.
98              
99             =cut
100              
101             sub tidy_ctype {
102 134     134 1 628 return $_[0]->{tidy_ctype};
103             }
104              
105             =head1 SEE ALSO
106              
107             L
108              
109             =head1 AUTHOR
110              
111             Steffen Mueller C<>
112              
113             =head1 COPYRIGHT & LICENSE
114              
115             Copyright 2009, 2010, 2011, 2012 Steffen Mueller
116              
117             This program is free software; you can redistribute it and/or
118             modify it under the same terms as Perl itself.
119              
120             =cut
121              
122             1;
123