Catalyst::Plugin::DateTime - DateTime plugin for Catalyst.


Catalyst-Plugin-DateTime documentation Contained in the Catalyst-Plugin-DateTime distribution.

Index


Code Index:

Catalyst::Plugin::DateTime - DateTime plugin for Catalyst.

SYNOPSIS

Top

    # In your application class	
    use Catalyst qw/DateTime/;




    # Use DateTime objects within your Catalyst app:
    my $dt = $c->datetime(); # will return a DateTime object with local date and time
    my $dt = $c->datetime(year => '2005', month => '01');

    $c->datetime->mdy(); # returns current date in mdy format (i.e. 01/01/2006)

    $c->dt(time_zone => 'Asia/Taipei'); # returns current date & time for argued time zone

METHODS

Top

datetime

Returns a DateTime object. If params are argued they will be passed to the DateTime->new() method. Exceptions thrown by DateTime will be caught by Catalyst::Exception.

If the argument list is empty, a DateTime object with the local date and time obtained via DateTime->now() will be returned.

Uses time_zone => local as a default.

dt

Alias to datetime.

DESCRIPTION

Top

This module's intention is to make the wonders of DateTime easily accesible within a Catalyst application via the Catalyst::Plugin interface.

It adds the methods datetime and dt to the Catalyst namespace.

AUTHOR

Top

James Kiser james.kiser@gmail.com

SEE ALSO

Top

Catalyst, DateTime

COPYRIGHT & LICENSE

Top


Catalyst-Plugin-DateTime documentation Contained in the Catalyst-Plugin-DateTime distribution.
package Catalyst::Plugin::DateTime;

use strict;
use warnings;

use Catalyst::Exception;
use DateTime;

our $VERSION = "0.03";

sub datetime {
	my $c = shift;
	my %params = @_;
	my $tz = delete $params{time_zone} || 'local';

	# use params if argued
	if (%params) {
		return DateTime->new(\%params)->set_time_zone($tz);
	}
	else { # otherwise use now
		return DateTime->now(time_zone => $tz);
	}
}

# alias $c->dt
*dt = \&datetime;

 
1;