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;
97 This is an obscure optimization that used to live in C<ExtUtils::ParseXS>
100 In a nutshell, this will check whether the output code
101 involves calling C<set_iv>, C<set_uv>, C<set_nv>, C<set_pv> or C<set_pvn>
102 to set the special C<$arg> placeholder to a new value
103 B<AT THE END OF THE OUTPUT CODE>. If that is the case, the code is
104 eligible for using the C<TARG>-related macros to optimize this.
105 Thus the name of the method: C<targetable>.
107 If the optimization can not be applied, this returns undef.
108 If it can be applied, this method returns a hash reference containing
109 the following information:
111 type: Any of the characters i, u, n, p
112 with_size: Bool indicating whether this is the sv_setpvn variant
113 what: The code that actually evaluates to the output scalar
114 what_size: If "with_size", this has the string length (as code, not constant)
120 return $self->{targetable} if exists $self->{targetable};
122 our $bal; # ()-balanced
131 # matches variations on (SV*)
134 \( \s* SV \s* \* \s* \) \s*
138 my $size = qr[ # Third arg (to setpvn)
142 my $code = $self->code;
144 # We can still bootstrap compile 're', because in code re.pm is
145 # available to miniperl, and does not attempt to load the XS code.
148 my ($type, $with_size, $arg, $sarg) =
152 sv_set([iunp])v(n)? # Type, is_setpvn
155 $sv_cast \$arg \s* , \s*
156 ( (??{ $bal }) ) # Set from
157 ( (??{ $size }) )? # Possible sizeof set-from
166 with_size => $with_size,
171 $self->{targetable} = $rv;
177 L<ExtUtils::Typemaps>
181 Steffen Mueller C<<smueller@cpan.org>>
183 =head1 COPYRIGHT & LICENSE
185 Copyright 2009-2011 Steffen Mueller
187 This program is free software; you can redistribute it and/or
188 modify it under the same terms as Perl itself.