Kiffin Gish wrote:
I use a standard generic services loader class (based on
Template::Plugin) whose responsibility is the proper fetching of all
service plugins located in a given directory:
----- Services.pm: start -----
package Plugin::Services;
use strict;
use warnings;
use base qw( Template::Plugin );
use Template::Plugin;
use Template::Iterator;
use Template::Plugins;
sub new {
...
for my $file (@allfiles) {
...
my ($data, $error) = $self->{_PROVIDER}->fetch($file, [EMAIL PROTECTED],
$self->{_CONTEXT});
if ($error) {
$self->_die("Cannot fetch file '$file' : error=$error")
} else {
push(@{$self->{_FETCHED}}, $data);
} }
...
}
sub list {
my $self = shift;
my $iter = Template::Iterator->new($self->{_FETCHED});
return $iter;
}
----- Services.pm: end -----
In my main config file, I check iterate through all of the services
and process the service page passing the service object which has
(hopefully) been found.
----- config/main: start -----
[% USE services = Services %]
[% FOREACH service IN services.list %]
[% IF service.info.name == tmpl_file %]
[% TRY %]
[% PROCESS service.html.tmpl service = service %]
[% CATCH %]
[% PROCESS error.html.tmpl %]
[% END %]
[% RETURN %] [% END %]
[% END %]
----- config/main: end -----
Finally, in the service html template file a call the run-method of
the given service as follows:
----- src/service.html.tmpl: begin -----
[% page.title = service.info.name
page.about = service.info.about %]
<p>
[% service.info.description %]
</p>
[% q.start_form( action = q.url ) %]
[% q.hidden( name = 'page', value = service.info.name ) %]
[% service.run %]
[% q.end_form.join(''); %]
----- src/service.html.tmpl: end -----
An example service plugin looks like this:
----- Plugin/Service/DFax.pm: start -----
package Plugin::Service::DFax;
use strict;
use warnings;
use lib qw(../../);
use base qw( Plugin::Service::Template );
sub run {
my ($self, $param) = @_;
my $results = "";
# [CODE]
...
return $results;
}
1;
----- Plugin/Service/DFax.pm: end -----
If '# [CODE]' precedes a syntax error, then I get the following error:
"Plugin::Services error - Cannot fetch file 'DFax' : error=255,
line: 68"
However, if [CODE] references a non-exiting routine, no error messages
appear, and the results are empty!
What gives, and how can I also catch this situation? Does this have to
do with some hidden autoload method that is catching and absorbing
this? If so, how can I disable it?
I hope that someone can help me out, thanks in advance.
Solved the problem by adding the following AUTOLOAD code to my
./Plugin/Service/Template.pm module file:
sub AUTOLOAD {
my $self = shift;
our $AUTOLOAD;
die( $self->{_CONTEXT}->throw( $self->{_CLASSNAME}, "Unknown
package::method called '$AUTOLOAD'" ) );
}
Easy as pie.
--
Kiffin Gish
Gouda, The Netherlands
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates