NAME
Apache2::Translation::_base - The Apache2::Translation provider interface
DESCRIPTION
A translation provider must implement the following interface. It is free to support more functions.
Methods
- new( NAME=>VALUE, ... )
-
the constructor. It is called once from the master Apache during its configuration.
- child_init
-
This method is optional. If defined it is called from a
PerlChildInitHandlerand can be used to do some initializations. TheDBprovider connects here to the database and decides to use a singleton or not. - start
-
This method is called at start of each uri translation. The DB provider checks the cache here.
- stop
-
is called after each uri translation.
- fetch( $key, $uri, $with_notes )
-
is called to fetch a list of blocks. The result is a list of arrays:
([block, order, action], [block, order, action], ...)If the adminstration WEB interface is to be used
fetchmust return a list of:([block, order, action, id], [block, order, action, id], ...)where
idis a unique key.If the
$with_notesparameter is truefetchis called from the admin interface and wants to fetch also notes. In this case the return value is a list like this:([block, order, action, id, note], [block, order, action, id, note], ...)Notes are comments on actions for the user of the admin interface. They are not evaluated otherwize.
The following interface is optional. It has to be implemented if the provider is to be used also with the administration WEB interface.
- can_notes
-
returns true if a provider supports notes in its current configuration.
- list_keys
-
returns a sorted list of known keys.
- list_keys_and_uris( $key )
-
$keyis a string.The function returns a sorted list of
[KEY, URI]pairs. If$keyis empty all pairs are returned. Otherwise only pairs where$key eq KEYare returned. - begin
- commit
- rollback
-
A change conducted via the WEB interface is a sequence of
update,insertordeleteoperations. Before it is startedbeginis called. If there has no error occuredcommitis called otherwiserollback.commitmust save the changes to the storage.rollbackmust cancel all changes. - update( [@old], [@new] )
- insert( [@new] )
- delete( [@old] )
-
All these functions return something >0 on success.
@oldis a list ofKEY, URI, BLOCK, ORDER, IDthat specifies an existing action. If there is no such action the functions must return0.@newis a list ofKEY, URI, BLOCK, ORDER, ACTIONthat is to be inserted or has to replace an existing action.
The following interface is optional.
- clear
-
deletes all entries from the provider. Is to be called within a
begin-commitwrapper. Returns boolean. - iterator
-
returns a function reference that can be used the following way to step all entries currently hold by the provider. Lists of blocks are traversed in ascending alphabetical order with
KEYas the major ordering element andURIthe minor. Within a block list elements are traversed in ascending numerical order withBLOCKas the major ordering element andORDERthe minor.my $iterator=$other->iterator; while( my $el=$iterator->() ) { # $el is an array ref as expected by insert(). }
The following interface is implemented by Apache2::Translation::_base itself and can be used.
- append( $other_provider, %options )
-
Expects a provider object that implements the
iteratorfunction.appendtheninsert()s all elements of$other_provider.If
drop_notesis passed as a true value in%optionsthen notes are not copied. - diff( $other_provider, %options )
-
If Algorithm::Diff and JSON::XS are installed this method computes a difference between 2 providers. If
keyoruriare given in%optionsthey act as filters. The difference is calculated only for elements that pass that filter. The value ofkeyorurican either be a string in which case the matching operation is a simpleeqor aRegexpobject (qr/.../).If
notesis specified in%optionsas a false value differences in notes only are disregarded.If
numbersis specified in%optionsas a false value differences inBLOCKandORDERnumbers only are disregarded.For more information about the output format see
diff()in Algorithm::Diff. - sdiff( $other_provider, %options )
-
Does the same as the
diffmethod but differs in the output format.For more information see
sdiff()in Algorithm::Diff. - dump( $format, $filehandle )
-
Requires the
iteratorfunction to be implemented and dumps all elements formatted according to$formatto$filehandle.Both parameters are optional. Standard
$filehandleisSTDOUT, standard format is:###################################################################### %{KEY} & %{URI} %{BLOCK}/%{ORDER}/%{ID} %{paction> ;ACTION} %{pnote> ;NOTE}$formatis an arbitrary string that contains substrings of the form%{flags NAME}where
NAMEis on ofKEY,URI,BLOCK,ORDER,ACTION,NOTEorID. These substrings are then replaced by the values for KEY, etc.flagsis optional. It is a semicolon separated list of strings. If given it must also be separated fromNAMEby a semicolon.Currently 2 flags are known:
p string
Trailing spaces are cut from the current value. Then all occurences of
\r?\nare replaced by\nstring. Also,stringis inserted at start if the current value.Example:
Suppose an ACTION holds a multilined value:
PerlHandler: sub { my $r=shift; $r->content_type( 'text/plain' ); $r->print( "OK\n" ); return 0; }Then %{paction> ;ACTION} will be formatted as:
action> PerlHandler: sub { action> my $r=shift; action> $r->content_type( 'text/plain' ); action> $r->print( "OK\n" ); action> return 0; action> }s l|t
slstrips off leading spaces andsttrailing spaces.
AUTHOR
Torsten Foertsch, <torsten.foertsch@gmx.net>
COPYRIGHT AND LICENSE
Copyright (C) 2005-2008 by Torsten Foertsch
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.