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