File Coverage

blib/lib/ExtUtils/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 ExtUtils::Typemaps::Type;
2 15     15   270 use 5.006001;
  15         55  
3 15     15   83 use strict;
  15         40  
  15         359  
4 15     15   81 use warnings;
  15         29  
  15         5407  
5             require ExtUtils::Typemaps;
6              
7             our $VERSION = '3.43_02';
8              
9             =head1 NAME
10              
11             ExtUtils::Typemaps::Type - Entry in the TYPEMAP section of a typemap
12              
13             =head1 SYNOPSIS
14              
15             use ExtUtils::Typemaps;
16             ...
17             my $type = $typemap->get_type_map('char*');
18             my $input = $typemap->get_input_map($type->xstype);
19              
20             =head1 DESCRIPTION
21              
22             Refer to L for details.
23             Object associates C with C, which is the index
24             into the in- and output mapping tables.
25              
26             =head1 METHODS
27              
28             =cut
29              
30             =head2 new
31              
32             Requires C and C parameters.
33              
34             Optionally takes C parameter.
35              
36             =cut
37              
38             sub new {
39 3245     3245 1 4714 my $prot = shift;
40 3245   66     7570 my $class = ref($prot)||$prot;
41 3245         6764 my %args = @_;
42              
43 3245 100       6080 if (!ref($prot)) {
44 1098 50 33     3589 if (not defined $args{xstype} or not defined $args{ctype}) {
45 0         0 die("Need xstype and ctype parameters");
46             }
47             }
48              
49 3245 100       13473 my $self = bless(
50             (ref($prot) ? {%$prot} : {proto => ''})
51             => $class
52             );
53              
54 3245 100       8115 $self->{xstype} = $args{xstype} if defined $args{xstype};
55 3245 100       6429 $self->{ctype} = $args{ctype} if defined $args{ctype};
56 3245         6974 $self->{tidy_ctype} = ExtUtils::Typemaps::tidy_type($self->{ctype});
57 3245 50       6675 $self->{proto} = $args{'prototype'} if defined $args{'prototype'};
58              
59 3245         8216 return $self;
60             }
61              
62             =head2 proto
63              
64             Returns or sets the prototype.
65              
66             =cut
67              
68             sub proto {
69 287 50   287 1 554 $_[0]->{proto} = $_[1] if @_ > 1;
70 287         1085 return $_[0]->{proto};
71             }
72              
73             =head2 xstype
74              
75             Returns the name of the XS type that this C type is associated to.
76              
77             =cut
78              
79             sub xstype {
80 426     426 1 1141 return $_[0]->{xstype};
81             }
82              
83             =head2 ctype
84              
85             Returns the name of the C type as it was set on construction.
86              
87             =cut
88              
89             sub ctype {
90 2204 50   2204 1 7849 return defined($_[0]->{ctype}) ? $_[0]->{ctype} : $_[0]->{tidy_ctype};
91             }
92              
93             =head2 tidy_ctype
94              
95             Returns the canonicalized name of the C type.
96              
97             =cut
98              
99             sub tidy_ctype {
100 2164     2164 1 6541 return $_[0]->{tidy_ctype};
101             }
102              
103             =head1 SEE ALSO
104              
105             L
106              
107             =head1 AUTHOR
108              
109             Steffen Mueller C<>
110              
111             =head1 COPYRIGHT & LICENSE
112              
113             Copyright 2009, 2010, 2011, 2012 Steffen Mueller
114              
115             This program is free software; you can redistribute it and/or
116             modify it under the same terms as Perl itself.
117              
118             =cut
119              
120             1;
121