This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Defer loading main module
[perl5.git] / dist / ExtUtils-ParseXS / lib / ExtUtils / Typemaps / Type.pm
CommitLineData
7320491e 1package ExtUtils::Typemaps::Type;
297f4492
S
2use 5.006001;
3use strict;
4use warnings;
5our $VERSION = '0.05';
6use Carp qw(croak);
65aa9bab 7require ExtUtils::Typemaps;
297f4492
S
8
9=head1 NAME
10
7320491e 11ExtUtils::Typemaps::Type - Entry in the TYPEMAP section of a typemap
297f4492
S
12
13=head1 SYNOPSIS
14
7320491e 15 use ExtUtils::Typemaps;
297f4492
S
16 ...
17 my $type = $typemap->get_type_map('char*');
18 my $input = $typemap->get_input_map($type->xstype);
19
20=head1 DESCRIPTION
21
7320491e 22Refer to L<ExtUtils::Typemaps> for details.
297f4492
S
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 croak("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};
7320491e 56 $self->{tidy_ctype} = ExtUtils::Typemaps::_tidy_type($self->{ctype});
297f4492
S
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
7320491e 105L<ExtUtils::Typemaps>
297f4492
S
106
107=head1 AUTHOR
108
109Steffen Mueller C<<smueller@cpan.org>>
110
111=head1 COPYRIGHT & LICENSE
112
0b19625b 113Copyright 2009-2011 Steffen Mueller
297f4492
S
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