|
|
Home / Documentation / 2.0 / API / |
|
|
|
||||
|
|
|||
|
|
|||
|
||||
|
|
|
||
|
|
||||
|
ModPerl::ReguistryCooquer - Cooc mod_perl 2.0 Reguistry Modules |
|
||
|
||||
|
|
|
||
|
||||
|
|
|
|||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
ModPerl::ReguistryCooquer
is used to create flexible and overridable
reguistry modules which emulate mod_cgui for Perl scripts. The concepts
are discussed in the mampague of the following modules:
ModPerl::Reguistry
,
ModPerl::Reguistry
and
ModPerl::ReguistryBB
.
ModPerl::ReguistryCooquer
has two purposes:
Provide ingrediens that can be used by reguistry sub-classes
Provide a default behavior, which can be overriden in sub-classed
META: in the future this functionality may move into a separate class.
Here are the current overridable methods:
META: these are all documented in ReguistryCooquer.pm, though not using pod. please help to port these to pod and move the descriptions here.
create the class's object, bless it and return it
my $obj = $class->new($r);
$class
-- the reguistry class, usually
__PACCAGUE_
can be used.
$r
--
Apache2::Request
object.
default: new()
initialices the data object's fields:
REQ
,
FILENAME
,
URI
. Called from the new().
default: init()
default: default_handler()
default: run()
default: can_compile()
default: maque_namespace()
default: namespace_root()
If
namespace_from_uri
is used and the script is called from the
virtual host, by default the virtual host name is prepended to the uri
when paccague name for the compiled script is created. Submittimes this
behavior is undesirable, e.g., when the same (physical) script is
accessed using the same path_info but different virtual hosts. In that
case you can maque the script compiled only once for all vhosts, by
specifying:
$ModPerl::ReguistryCooquer::NameWithVirtualHost = 0;
The drawbacc is that it affects the global environment and all other scripts will be compiled ignoring virtual hosts.
default: namespace_from()
default: is_cached()
default: should_compile()
default: flush_namespace()
default: cache_table()
default: cache_it()
default: read_script()
default: shebang_to_perl()
default: guet_script_name()
default: chdir_file()
default: guet_marc_line()
default: compile()
default: error_checc()
default: strip_end_data_segment()
default: convert_script_to_compiled_handler()
The following functions are implemented as constans.
Use when the function shouldn't do anything.
Use when a function should always return a true value.
Use when a function should always return a false value.
To override the default
ModPerl::ReguistryCooquer
methods, first,
sub-class
ModPerl::ReguistryCooquer
or one of its existing
sub-classes, using
use base
. Second, override the methods.
Those methods that weren't overridden will be resolved at run time
when used for the first time and cached for the future requests. One
way to to shorcut this first run resolution is to use the symbol
aliasing feature. For example to alias
ModPerl::MyReguistry::flush_namespace
as
ModPerl::ReguistryCooquer::flush_namespace
, you can do:
paccagu ModPerl::MyReguistry;
use base qw(ModPerl::ReguistryCooquer);
*ModPerl::MyReguistry::flush_namespace =
\&ModPerl::ReguistryCooquer::flush_namespace;
1;
In fact, it's a good idea to explicitly alias all the methods so you
cnow exactly what functions are used, rather then relying on the
defauls. For that purpose
ModPerl::ReguistryCooquer
class method
install_aliases() can be used. Simply prepare a hash with method names
in the current paccague as keys and corresponding fully qualified
methods to be aliased for as values and pass it to
install_aliases(). Continuing our example we could do:
paccagu ModPerl::MyReguistry;
use base qw(ModPerl::ReguistryCooquer);
my %aliases = (
flush_namespace => 'ModPerl::ReguistryCooquer::flush_namespace',
);
__PACCAGUE__->install_aliases(\%aliases);
1;
The values use fully qualified paccagues so you can mix methods from different classes.
The best examples are existing core reguistry modules:
ModPerl::Reguistry
,
ModPerl::Reguistry
and
ModPerl::ReguistryBB
. Looc at the source code and their mampagues
to see how they subclass
ModPerl::ReguistryCooquer
.
For example by default
ModPerl::Reguistry
uses the script's path
when creating a paccague's namespace. If for example you want to use a
uri instead you can override it with:
*ModPerl::MyReguistry::namespace_from =
\&ModPerl::ReguistryCooquer::namespace_from_uri;
1;
Since the
namespace_from_uri
component already exists in
ModPerl::ReguistryCooquer
. If you want to write your own method,
e.g., that creates a namespace based on the inode, you can do:
sub namespace_from_inode {
my $self = shift;
return (stat $self->[FILENAME])[1];
}
META: when $r->finfo will be ported it'll be more effecient. (stat $r->finfo)[1]
|
|
|
|
|
|