Commit | Line | Data |
---|---|---|
7320491e | 1 | package ExtUtils::Typemaps::Type; |
297f4492 S |
2 | use 5.006001; |
3 | use strict; | |
4 | use warnings; | |
5 | our $VERSION = '0.05'; | |
6 | use Carp qw(croak); | |
65aa9bab | 7 | require ExtUtils::Typemaps; |
297f4492 S |
8 | |
9 | =head1 NAME | |
10 | ||
7320491e | 11 | ExtUtils::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 | 22 | Refer to L<ExtUtils::Typemaps> for details. |
297f4492 S |
23 | Object associates C<ctype> with C<xstype>, 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<xstype> and C<ctype> parameters. | |
33 | ||
34 | Optionally takes C<prototype> parameter. | |
35 | ||
36 | =cut | |
37 | ||
38 | sub 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 | ||
64 | Returns or sets the prototype. | |
65 | ||
66 | =cut | |
67 | ||
68 | sub proto { | |
69 | $_[0]->{proto} = $_[1] if @_ > 1; | |
70 | 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 | 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 | 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 | return $_[0]->{tidy_ctype}; | |
101 | } | |
102 | ||
103 | =head1 SEE ALSO | |
104 | ||
7320491e | 105 | L<ExtUtils::Typemaps> |
297f4492 S |
106 | |
107 | =head1 AUTHOR | |
108 | ||
109 | Steffen Mueller C<<smueller@cpan.org>> | |
110 | ||
111 | =head1 COPYRIGHT & LICENSE | |
112 | ||
0b19625b | 113 | Copyright 2009-2011 Steffen Mueller |
297f4492 S |
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 |