Yann:
Why not do something like:
my $mydate = DateTime(year=>2003, minute=>2,hour=>4);
$$vars{"mydate"} = $mydate;
and then, in the template:
[% mydate.ymd('-') %]
[% mydate.today.date %]
If the dates are not known until the template is run, then something
like:
$$vars{"getdate"}=sub {function with 3 parms, returning a DateTime
object};
and then, in your template:
[% mydate = getdate(2003,07,02) %]
Is there something flawed about this approach?
Rafael Caceres
On Fri, 2003-08-01 at 05:46, Yann Kerherv� wrote:
>
> Hello the list,
>
> I really love plugins, but I'm not fond of writing too simple plugin
> like this one for the wonderfull DateTime :
>
>
> package Template::Plugin::DateTime;
>
> use strict;
> use base qw( DateTime Template::Plugin );
> sub new {
> my $proto = shift;
> my $context = shift;
> return $proto::SUPER->new(@_);
> }
> 1;
>
> [% USE mydate = DateTime(year=> 2003, minute=> 2, hour=> 4) %]
> [% mydate.ymd('-') %]
> [% mydate.today.date %]
>
>
> Is there a way to avoid this job in vanilla TT ?
> I've searched in archives without success.
>
> One way to do the job could be to pass the package name as first
> parameter.
>
> [% USE mydate=LazyLoad('DateTime', year=> 2004, minute=> 2, hour=> 4)
> %]
>
> and the Template::Plugin::LazyLoad code :
>
> sub new {
> my $class = shift;
> my $context = shift;
> my $package = shift;
> eval "require $package";
> if ($@) {
> $class->error("couldn't load $package");
> return undef;
> }
> return $package->new(@_);
> }
>
> It's a dirty "You'd better know what you're doing" hack... but it just
> works (at least for the new constructor).
> Should Template::Plugin::DateTime enter CPAN ?
>
> Better anyone ?
>
>
> Yann
>
>
> _______________________________________________
> templates mailing list
> [EMAIL PROTECTED]
> http://lists.template-toolkit.org/mailman/listinfo/templates
>
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates