pragma - utility functions for lexically-scoped pragmas
package MyPragma;
use pragma;
sub import {
my ($class, $value) = @_;
# check $value here...
install_pragma_value($class, $value);
}
1;
This should be the abstract for pragma.
The abstract is used when making PPD (Perl Package Description) files.
If you don't want an ABSTRACT you should also edit Makefile.PL to
remove the ABSTRACT_FROM option.
Every statement in a Perl program has a list of 'pragmas' associated
with it. The pragmas are hints to modules or to the Perl interpreter
that certain types of behavior should be changed. For example, a
pragma might indicate to Perl that the strict 'vars' checks should
be performed for that statement.
Each pragma has a name, which is a string, and perhaps some associated
data. The data can be anything, but this module assumes that the data
will be a regular Perl scalar (which, of course, could be a reference
to a more complex data structure).
Pragmas must be set at compile time. They can be looked up at run
time. See perlpragma for complete details about the internals of
pragmas and the C interface to pragmas.
Pragmatic modules may inherit the import subroutine from the
pragma module itself, which performs the appropriate installation.
If you want to define a pragma called mypragma, create a
mypragma.pm file as indicated in the SYNOPSIS section above.
Then any other part of the program may use
{
...
use mypragma "Carrots";
...
}
This declares that the pragma mypragma is in scope to the end of
the enclosing block. The name of the pragma is 'mypragma'; the value
is "Carrots". The value "Carrots" will not be used by any
module other than the mypragma module.
A more typical use of the pragma value would be:
{
...
use mypragma "on";
...
use mypragma "off";
...
}
Or perhaps:
{
...
use strict 'vars';
...
use strict 'refs', 'subs';
...
}
- install_pragma_value($name, $value)
-
This function associates a pragma with rest of the block that is
presently being compiled. The scope of the pragma is from the
statement currently being compiled to the end of the enclosing block.
The $name may be used to retrieve the specified $value, which
has no special meaning
install_pragma_value should be called at compile time, from within
an import subroutine. .
- current_pragma_value($name, $value)
-
Looks in the pragma list for the currently executing statement for the
first pragma named $name. If it finds one, it returns the
corresponding $value; otherwise, it returns undef.
- caller_pragma_value($name, $value)
-
Like current_pragma_value, but for the currently executing
statement in the calling function instead of the current function.
perlvar/``%^H''
Mark Jason Dominus, <mjd@plover.com>
Copyright 2003 Mark Jason Dominus.
This library is free software; you may redistribute it and/or modify
it under the same terms as Perl itself.