1 package ExtUtils::Typemaps::OutputMap;
9 ExtUtils::Typemaps::OutputMap - Entry in the OUTPUT section of a typemap
13 use ExtUtils::Typemaps;
15 my $output = $typemap->get_output_map('T_NV');
16 my $code = $output->code();
21 Refer to L<ExtUtils::Typemaps> for details.
29 Requires C<xstype> and C<code> parameters.
35 my $class = ref($prot)||$prot;
39 if (not defined $args{xstype} or not defined $args{code}) {
40 die("Need xstype and code parameters");
45 (ref($prot) ? {%$prot} : {})
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;
58 Returns or sets the OUTPUT mapping code for this entry.
63 $_[0]->{code} = $_[1] if @_ > 1;
69 Returns the name of the XS type of the OUTPUT map.
74 return $_[0]->{xstype};
79 Returns a cleaned-up copy of the code to which certain transformations
80 have been applied to make it more ANSI compliant.
86 my $code = $self->code;
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;
98 This is an obscure optimization that used to live in C<ExtUtils::ParseXS>
101 In a nutshell, this will check whether the output code
102 involves calling C<set_iv>, C<set_uv>, C<set_nv>, C<set_pv> or C<set_pvn>
103 to set the special C<$arg> placeholder to a new value
104 B<AT THE END OF THE OUTPUT CODE>. If that is the case, the code is
105 eligible for using the C<TARG>-related macros to optimize this.
106 Thus the name of the method: C<targetable>.
108 If the optimization can not be applied, this returns undef.
109 If it can be applied, this method returns a hash reference containing
110 the following information:
112 type: Any of the characters i, u, n, p
113 with_size: Bool indicating whether this is the sv_setpvn variant
114 what: The code that actually evaluates to the output scalar
115 what_size: If "with_size", this has the string length (as code,
122 return $self->{targetable} if exists $self->{targetable};
124 our $bal; # ()-balanced
133 # matches variations on (SV*)
136 \( \s* SV \s* \* \s* \) \s*
140 my $size = qr[ # Third arg (to setpvn)
144 my $code = $self->code;
146 # We can still bootstrap compile 're', because in code re.pm is
147 # available to miniperl, and does not attempt to load the XS code.
150 my ($type, $with_size, $arg, $sarg) =
154 sv_set([iunp])v(n)? # Type, is_setpvn
157 $sv_cast \$arg \s* , \s*
158 ( (??{ $bal }) ) # Set from
159 ( (??{ $size }) )? # Possible sizeof set-from
168 with_size => $with_size,
173 $self->{targetable} = $rv;
179 L<ExtUtils::Typemaps>
183 Steffen Mueller C<<smueller@cpan.org>>
185 =head1 COPYRIGHT & LICENSE
187 Copyright 2009-2011 Steffen Mueller
189 This program is free software; you can redistribute it and/or
190 modify it under the same terms as Perl itself.