DateTime-Format-Builder

 view release on metacpan or  search on metacpan

lib/DateTime/Format/Builder/Parser/Quick.pm  view on Meta::CPAN

package DateTime::Format::Builder::Parser::Quick;

use strict;
use warnings;

our $VERSION = '0.83';

our %dispatch_data;

use Params::Validate qw( SCALAR OBJECT CODEREF validate );

use parent qw( DateTime::Format::Builder::Parser );

__PACKAGE__->valid_params(
    Quick => {
        type      => SCALAR | OBJECT,
        callbacks => {
            good_classname => sub {
                ( ref $_[0] ) or ( $_[0] =~ /^\w+[:'\w+]*\w+/ );
            },
        }
    },
    method => {
        optional => 1,
        type     => SCALAR | CODEREF,
    },
);

sub create_parser {
    my ( $self, %args ) = @_;
    my $class  = $args{Quick};
    my $method = $args{method};
    $method = 'parse_datetime' unless defined $method;
    eval "use $class";
    die $@ if $@;

    return sub {
        my ( $self, $date ) = @_;
        return unless defined $date;
        my $rv = eval { $class->$method($date) };
        return $rv if defined $rv;
        return;
    };
}

1;

# ABSTRACT: Use another formatter, simply

__END__

=pod

=encoding UTF-8

=head1 NAME

DateTime::Format::Builder::Parser::Quick - Use another formatter, simply

=head1 VERSION

version 0.83

=head1 SYNOPSIS

    use DateTime::Format::Builder (
        parsers => {
            parse_datetime => [
                { Quick => 'DateTime::Format::HTTP' },
                { Quick => 'DateTime::Format::Mail' },
                { Quick => 'DateTime::Format::IBeat' },
            ]
        }
    );

    # is the same as



( run in 0.716 second using v1.01-cache-2.11-cpan-39bf76dae61 )