Filter::Template::UseBytes - conditionally use bytes.pm depending on availability


Filter-Template documentation Contained in the Filter-Template distribution.

Index


Code Index:

NAME

Top

Filter::Template::UseBytes - conditionally use bytes.pm depending on availability

SYNOPSIS

Top

	use Filter::Template ( isa => "Filter::Template::UseBytes" );

	print "Phi length in characters: ", length(chr(0x618)), "\n";
	{% use_bytes %}
	print "Phi length in bytes: ", length(chr(0x618)), "\n";

DESCRIPTION

Top

The UseBytes template evaluates to use bytes; if Perl 5.005_55 or later is running. Otherwise it evaluates to an empty string, which does nothing but doesn't throw an exception either.

BUGS

Top

All the caveats of Filter::Template apply here.

SEE ALSO

Top

Filter::Template.

AUTHOR & COPYRIGHT

Top


Filter-Template documentation Contained in the Filter-Template distribution.

package Filter::Template::UseBytes;
use Filter::Template;

use vars qw($VERSION);
$VERSION = '1.00';

# Make the "use_bytes" template evaluate to C<use bytes;> in Perl on or
# after 5.005_55.  Systems before then don't have the option, so the
# template evaluates to emptiness.

# Template definitions can't be indented, so this looks ugly.

# The "# include" modifier causes the conditional to be evaluated at
# compile time.  This turns regular if/else logic into the moral
# equivalent of the C preprocessor's #if/#else.

# Because the conditionals are evaluated at compile time, it's
# imperative that the things they test be defined.  The BEGIN block
# makes sure HAS_BYTES is defined before the tests are executed.

BEGIN {
	eval "use bytes; sub HAS_BYTES () { 1 }";
	eval "sub HAS_BYTES () { 0 }" if $@;
};

if (HAS_BYTES) { # include
template use_bytes {
	use bytes;
}
} else { # include
template use_bytes {
}
} # include

1;

__END__