This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
5aca32c09b5bb1561216ecc839ad615e4e3bd73d
[perl5.git] / dist / ExtUtils-ParseXS / lib / ExtUtils / Typemaps / OutputMap.pm
1 package ExtUtils::Typemaps::OutputMap;
2 use 5.006001;
3 use strict;
4 use warnings;
5 #use Carp qw(croak);
6
7 =head1 NAME
8
9 ExtUtils::Typemaps::OutputMap - Entry in the OUTPUT section of a typemap
10
11 =head1 SYNOPSIS
12
13   use ExtUtils::Typemaps;
14   ...
15   my $output = $typemap->get_output_map('T_NV');
16   my $code = $output->code();
17   $output->code("...");
18
19 =head1 DESCRIPTION
20
21 Refer to L<ExtUtils::Typemaps> for details.
22
23 =head1 METHODS
24
25 =cut
26
27 =head2 new
28
29 Requires C<xstype> and C<code> parameters.
30
31 =cut
32
33 sub new {
34   my $prot = shift;
35   my $class = ref($prot)||$prot;
36   my %args = @_;
37
38   if (!ref($prot)) {
39     if (not defined $args{xstype} or not defined $args{code}) {
40       die("Need xstype and code parameters");
41     }
42   }
43
44   my $self = bless(
45     (ref($prot) ? {%$prot} : {})
46     => $class
47   );
48
49   $self->{xstype} = $args{xstype} if defined $args{xstype};
50   $self->{code} = $args{code} if defined $args{code};
51   $self->{code} =~ s/^(?=\S)/\t/mg;
52
53   return $self;
54 }
55
56 =head2 code
57
58 Returns or sets the OUTPUT mapping code for this entry.
59
60 =cut
61
62 sub code {
63   $_[0]->{code} = $_[1] if @_ > 1;
64   return $_[0]->{code};
65 }
66
67 =head2 xstype
68
69 Returns the name of the XS type of the OUTPUT map.
70
71 =cut
72
73 sub xstype {
74   return $_[0]->{xstype};
75 }
76
77 =head2 cleaned_code
78
79 Returns a cleaned-up copy of the code to which certain transformations
80 have been applied to make it more ANSI compliant.
81
82 =cut
83
84 sub cleaned_code {
85   my $self = shift;
86   my $code = $self->code;
87
88   # Move C pre-processor instructions to column 1 to be strictly ANSI
89   # conformant. Some pre-processors are fussy about this.
90   $code =~ s/^\s+#/#/mg;
91
92   return $code;
93 }
94
95 =head1 SEE ALSO
96
97 L<ExtUtils::Typemaps>
98
99 =head1 AUTHOR
100
101 Steffen Mueller C<<smueller@cpan.org>>
102
103 =head1 COPYRIGHT & LICENSE
104
105 Copyright 2009-2011 Steffen Mueller
106
107 This program is free software; you can redistribute it and/or
108 modify it under the same terms as Perl itself.
109
110 =cut
111
112 1;
113