Linux SoftwareProgrammingLibrariesDateTime::Format::Builder::Tutorial 0.7807

DateTime::Format::Builder::Tutorial 0.7807


DateTime::Format::Builder::Tutorial is a quick class on using Builder. CREATING A CLASS As most people who are writing modules
Developer:   Iain Truskett
      more software by author →
Price:  0.00
License:   Perl Artistic License
File size:   47K
Language:   
OS:   
Rating:   0 /5 (0 votes)
Your vote:  
enlarge screenshot


DateTime::Format::Builder::Tutorial is a quick class on using Builder.

CREATING A CLASS

As most people who are writing modules know, you start a package with a package declaration and some indication of module version:

package DateTime::Format::ICal;
our $VERSION = '0.04';

After that, you call Builder with some options. There are only a few (detailed later). Right now, we're only interested in parsers.

use DateTime::Format::Builder
(
parsers => {
...
}
);

The parsers option takes a reference to a hash of method names and specifications:

parsers => {
parse_datetime => ... ,
parse_datetime_with_timezone => ... ,
...
}

Builder will create methods in your class, each method being a parser that follows the given specifications. It is strongly recommended that one method is called parse_datetime, be it a Builder created method or one of your own.

In addition to creating any of the parser methods it also creates a new() method that can instantiate (or clone) objects of this class. This behaviour can be modified with the constructor option, but we don't need to know that yet.

Each value corresponding to a method name in the parsers list is either a single specification, or a list of specifications. We'll start with the simple case.

parse_briefdate => {
params => [ qw( year month day ) ],
regex => qr/^(dddd)(dd)(dd)$/,
},

This will result in a method named parse_briefdate which will take strings in the form 20040716 and return DateTime objects representing that date. A user of the class might write:

use DateTime::Format::ICal;
my $date = "19790716";
my $dt = DateTime::Format::ICal->parse_briefdate( $date );
print "My birth month is ", $dt->month_name, "n";

The regex is applied to the input string, and if it matches, then $1, $2, ... are mapped to the params given and handed to DateTime->new(). Essentially:

my $rv = DateTime->new( year => $1, month => $2, day => $3 );

There are more complicated things one can do within a single specification, but we'll cover those later.

Often, you'll want a method to be able to take one string, and run it against multiple parser specifications. It would be very irritating if the user had to work out what format the datetime string was in and then which method was most appropriate.

So, Builder lets you specify multiple specifications:

parse_datetime => [
{
params => [ qw( year month day hour minute second ) ],
regex => qr/^(dddd)(dd)(dd)T(dd)(dd)(dd)$/,
},
{
params => [ qw( year month day hour minute ) ],
regex => qr/^(dddd)(dd)(dd)T(dd)(dd)$/,
},
{
params => [ qw( year month day hour ) ],
regex => qr/^(dddd)(dd)(dd)T(dd)$/,
},
{
params => [ qw( year month day ) ],
regex => qr/^(dddd)(dd)(dd)$/,
},
],

It's an arrayref of specifications. A parser will be created that will try each of these specifications sequentially, in the order you specified.

Requirements:
  • Perl
    tags datetime format  year month  month day  parse datetime  day hour  format ical  parse briefdate  string and  hour minute  datetime new  day regex  single specification  format builder  

    Download DateTime::Format::Builder::Tutorial 0.7807


     http://mirrors.evolva.ro/CPAN/authors/id/D/DR/DROLSKY/DateTime-Format-Builder-0.7807.tar.gz


    Authors software

    DateTime::Format::Excel 0.2901 (by Iain Truskett)
    DateTime::Format::Excel is a Perl module that can convert between DateTime and Excel dates.

    SYNOPSIS

    use DateTime::Format::

    DateTime::Format::Builder::Tutorial 0.7807 (by Iain Truskett)
    DateTime::Format::Builder::Tutorial is a quick class on using Builder.

    CREATING A CLASS

    As most people who are writing modules


    Similar software

    DateTime::Format::Builder::Tutorial 0.7807 (by Iain Truskett)
    DateTime::Format::Builder::Tutorial is a quick class on using Builder.

    CREATING A CLASS

    As most people who are writing modules

    DateTime::Format::Excel 0.2901 (by Iain Truskett)
    DateTime::Format::Excel is a Perl module that can convert between DateTime and Excel dates.

    SYNOPSIS

    use DateTime::Format::

    DateTime::Format::Epoch::DotNet 0.10 (by Eugene van der Pijli)
    DateTime::Format::Epoch::DotNet is a Perl module that can convert DateTimes to/from .NET epoch seconds.

    SYNOPSIS

    use DateTime

    DateTime::Format::Epoch::MacOS 0.10 (by Eugene van der Pijli)
    DateTime::Format::Epoch::MacOS is a Perl module that can convert DateTimes to/from Mac OS epoch seconds.

    SYNOPSIS

    use DateTim

    DateTime::Format::Epoch 0.10 (by Eugene van der Pijli)
    DateTime::Format::Epoch is a Perl module that can convert DateTimes to/from epoch seconds.

    SYNOPSIS

    use DateTime::Format::Epo

    Data::Faker::DateTime 0.07 (by Jason Kohles)
    Data::Faker::DateTime is a Data::Faker plugin.

    DATA PROVIDERS

    unixtime

    Return a unix time (seconds since the epoch) for a ra

    DateTime::Format::Epoch::TAI64 0.10 (by Eugene van der Pijll)
    DateTime::Format::Epoch::TAI64 is a Perl module that can convert DateTimes to/from TAI64 values.

    SYNOPSIS

    use DateTime::Forma

    DateTime::Format::Epoch::TJD 0.10 (by Eugene van der Pijli)
    DateTime::Format::Epoch::TJD is a Perl module that can convert DateTimes to/from Truncated Julian Days.

    SYNOPSIS

    use DateTime

    DateTime::Format::Epoch::MJD 0.10 (by Eugene van der Pijll)
    DateTime::Format::Epoch::MJD is a Perl module that can convert DateTimes to/from Modified Julian Days.

    SYNOPSIS

    use DateTime:

    DateTime::Format::Epoch::Lilian 0.10 (by Eugene van der Pijll)
    DateTime::Format::Epoch::Lilian is a Perl module to convert DateTimes to/from Lilian Days.

    SYNOPSIS

    use DateTime::Format::Epo


    Other software in this category

    zlib 1.2.3 (by Jean-loup Gailly)
    zlib is designed to be a free, general-purpose, legally unencumbered, lossless data-compression library for use on virtually any comp

    libjpeg v6b (by Independent JPEG Group)
    libjpeg is a library for handling the JPEG (JFIF) image format

    OpenSSL 0.9.7c (by The OpenSSL Project Team)
    The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implement

    libxml2 2.6.27 (by DV)
    Libxml2 is the XML C parser and toolkit developed for the Gnome project (but usable outside of the Gnome platform), libxml2 library i

    GNU C library 2.4 (by Andreas Jaeger)
    GNU C library (glibc) is one of the most important components of GNU Hurd and most modern Linux distributions.

    GNU C library is us

  •     search


    Featured Software

    jEdit 4.3 pre8
    jEdit is an Open Source text editor written in Java

    Opera 9.02
    Surf the Internet in a safer, faster, and easier way with Opera browser

    GNU Aspell 0.60.4
    GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell


    Subscribe in Rojo
    Google Reader
    Add to My Yahoo!

    Add to My AOL
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    Add 'nixbit linux software' to Newsburst from CNET News.com
    del.icio.us nixbit linux software


    Top tags