File Coverage

blib/lib/ExtUtils/Typemaps/Type.pm
Criterion Covered Total %
statement 24 25 96.0
branch 13 16 81.2
condition 3 6 50.0
subroutine 8 8 100.0
pod 5 5 100.0
total 53 60 88.3


line stmt bran cond sub pod time code
1             package ExtUtils::Typemaps::Type;
2 16     16   297 use 5.006001;
  16         63  
3 16     16   96 use strict;
  16         35  
  16         455  
4 16     16   77 use warnings;
  16         33  
  16         13317  
5             require ExtUtils::Typemaps;
6              
7             our $VERSION = '3.61';
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. Note however that the method to
35             get/set the value is called C rather than .
36              
37             =cut
38              
39             sub new {
40 99149     99149 1 159863 my $prot = shift;
41 99149   66     278082 my $class = ref($prot)||$prot;
42 99149         214556 my %args = @_;
43              
44 99149 100       215352 if (!ref($prot)) {
45 33066 50 33     126834 if (not defined $args{xstype} or not defined $args{ctype}) {
46 0         0 die("Need xstype and ctype parameters");
47             }
48             }
49              
50 99149 100       701256 my $self = bless(
51             (ref($prot) ? {%$prot} : {proto => ''})
52             => $class
53             );
54              
55 99149 100       313711 $self->{xstype} = $args{xstype} if defined $args{xstype};
56 99149 100       230271 $self->{ctype} = $args{ctype} if defined $args{ctype};
57 99149         258943 $self->{tidy_ctype} = ExtUtils::Typemaps::tidy_type($self->{ctype});
58 99149 100       236467 $self->{proto} = $args{'prototype'} if defined $args{'prototype'};
59              
60 99149         312731 return $self;
61             }
62              
63             =head2 proto
64              
65             Returns or sets the prototype.
66              
67             =cut
68              
69             sub proto {
70 614 50   614 1 1618 $_[0]->{proto} = $_[1] if @_ > 1;
71 614         2055 return $_[0]->{proto};
72             }
73              
74             =head2 xstype
75              
76             Returns the name of the XS type that this C type is associated to.
77              
78             =cut
79              
80             sub xstype {
81 1629     1629 1 7007 return $_[0]->{xstype};
82             }
83              
84             =head2 ctype
85              
86             Returns the name of the C type as it was set on construction.
87              
88             =cut
89              
90             sub ctype {
91 66140 50   66140 1 270027 return defined($_[0]->{ctype}) ? $_[0]->{ctype} : $_[0]->{tidy_ctype};
92             }
93              
94             =head2 tidy_ctype
95              
96             Returns the canonicalized name of the C type.
97              
98             =cut
99              
100             sub tidy_ctype {
101 66100     66100 1 320196 return $_[0]->{tidy_ctype};
102             }
103              
104             =head1 SEE ALSO
105              
106             L
107              
108             =head1 AUTHOR
109              
110             Steffen Mueller C<>
111              
112             =head1 COPYRIGHT & LICENSE
113              
114             Copyright 2009, 2010, 2011, 2012 Steffen Mueller
115              
116             This program is free software; you can redistribute it and/or
117             modify it under the same terms as Perl itself.
118              
119             =cut
120              
121             1;
122