Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

tokuhirom (7396)

  (email not shown publicly)

Journal of tokuhirom (7396)

Saturday December 02, 2006
01:52 AM


[ #31785 ]

I think, generate DateTime instance from is very frequent and very painful.

Yes, I wrote the Sledge::Plugin::Inflate::DateTime.

You just write the

package Your::Pages;
use Sledge::Plguin::Inflate;
use Sledge::Plguin::Inflate::DateTime;

then, you can inflate DateTime object easily.

sub dispatch_foo {
  my $self = shift;
  $self->stash->{date} = $self->r->inflate('date');

And, Sledge::Plguin::Inflate::DateTime and HTML::DateSelector go together!

package Sledge::Plugin::Inflate::DateTime;
use strict;
use warnings;
use DateTime;
sub import {
    my $pkg = caller(0);
    no strict 'refs';
    *{"$pkg\::add_inflate_rule_ymd"} = sub {
        my ($class, $key, $datetime) = @_;
        $datetime ||= 'DateTime';
            $key => sub {
                my ( $self, ) = @_;
                my %args;
                $args{year}  = $self->r->param("$key\_year");
                $args{month} = $self->r->param("$key\_month");
                $args{day}   = $self->r->param("$key\_day");
                if ( $args{year} && $args{month} && $args{day} ) {
                    return $datetime->new(%args);
    package Your::Pages;
    use Sledge::Plugin::Inflate::DateTime;
    # simple way
    # you can use your customized DateTime class.
    __PACKAGE__->add_inflate_rule_ymd('from' => 'Your::DateTime');

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.