Sub-Attribute-Prototype
view release on metacpan or search on metacpan
that newer versions of perl would do; subject to some caveats.
Caveats
The following caveats should be noted about the pre-5.20 polyfilled
version of the :prototype attribute.
* Due to the way that attributes are applied to functions, it is not
possible to apply the prototype immediately during compiletime.
Instead, they must be deferred until a slightly later time. The
earliest time that can feasibly be implemented is UNITCHECK time of
the importing module.
This has the unfortunate downside that function prototypes are NOT
visible to later functions in the module itself, though they are
visible to the importing code in the usual way. This means that
exported functions will work just fine from the perspective of a
module that uses them, they cannot be used internally within the
module itself.
Because this limitation only applies to the polyfilled version of the
* Perl versions older than 5.20 will provoke a warning in the
reserved category when they encounter the attribute syntax provided
by this polyfill, even though the polyfill has consumed the
attribute. In order not to cause this warning to appear to users of
modules using this syntax, it is necessary for this polyfill to
suppress the entire reserved warning category. This means that all
such warnings will be silenced, including those about different
attributes.
* Because core perl does not have a built-in way for exporter to
inject a UNITCHECK block into their importer, it is necessary to use
a non-core XS module, B::CompilerPhase::Hook, to provide this. As a
result, this polyfill has non-core depenencies when running on older
perl versions, and this dependency includes XS (i.e. compiled) code,
and is no longer Pure Perl. It will not be possible to use tools such
as App::FatPacker to bundle this dependency in order to ship a
pure-perl portable script.
It should be stressed that none of these limitations apply when running
on a version of perl 5.20 or later. Though in that case there is no
need to use this polyfill at all, because the :prototype attribute will
lib/Sub/Attribute/Prototype.pm view on Meta::CPAN
The following caveats should be noted about the pre-5.20 polyfilled version
of the C<:prototype> attribute.
=over 4
=item *
Due to the way that attributes are applied to functions, it is not possible
to apply the prototype immediately during compiletime. Instead, they must be
deferred until a slightly later time. The earliest time that can feasibly be
implemented is C<UNITCHECK> time of the importing module.
This has the unfortunate downside that function prototypes are B<NOT> visible
to later functions in the module itself, though they are visible to the
importing code in the usual way. This means that exported functions will work
just fine from the perspective of a module that C<use>s them, they cannot be
used internally within the module itself.
Because this limitation only applies to the polyfilled version of the
attribute for older versions of perl, it means the behavior will differ on a
newer version of perl. Thus it is important that if you wish call a prototyped
lib/Sub/Attribute/Prototype.pm view on Meta::CPAN
category when they encounter the attribute syntax provided by this polyfill,
even though the polyfill has consumed the attribute. In order not to cause this
warning to appear to users of modules using this syntax, it is necessary for
this polyfill to suppress the entire C<reserved> warning category. This means
that all such warnings will be silenced, including those about different
attributes.
=item *
Because core perl does not have a built-in way for exporter to inject a
C<UNITCHECK> block into their importer, it is necessary to use a non-core XS
module, L<B::CompilerPhase::Hook>, to provide this. As a result, this polyfill
has non-core depenencies when running on older perl versions, and this
dependency includes XS (i.e. compiled) code, and is no longer Pure Perl. It
will not be possible to use tools such as L<App::FatPacker> to bundle this
dependency in order to ship a pure-perl portable script.
=back
It should be stressed that none of these limitations apply when running on a
version of perl 5.20 or later. Though in that case there is no need to use
lib/Sub/Attribute/Prototype.pm view on Meta::CPAN
push @prototypes, [ $code, $prototype ];
next;
}
push @ret, $attr;
}
return @ret;
};
{ no strict 'refs'; *{"${pkg}::MODIFY_CODE_ATTRIBUTES"} = $MODIFY_CODE_ATTRIBUTES }
B::CompilerPhase::Hook::enqueue_UNITCHECK( sub {
foreach ( @prototypes ) {
my ( $code, $prototype ) = @$_;
Sub::Util::set_prototype( $_->[1], $_->[0] );
}
} );
warnings->unimport( qw( reserved ) );
}
=head1 AUTHOR
( run in 2.573 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )