File: Fall.pm

package info (click to toggle)
libdatetime-format-builder-perl 0.8300-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 504 kB
  • sloc: perl: 1,236; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -w
use strict;

=pod

This example shows a simple fall through parser that tries
a few of the other formatting modules, _then_ fails.

=cut

package DateTime::Format::Fall;
use DateTime::Format::HTTP;
use DateTime::Format::Mail;
use DateTime::Format::IBeat;

use DateTime::Format::Builder (
    parsers => {
        parse_datetime => [
            sub {
                eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) };
            },
            sub {
                eval { DateTime::Format::Mail->parse_datetime( $_[1] ) };
            },
            sub {
                eval { DateTime::Format::IBeat->parse_datetime( $_[1] ) };
            },
        ]
    }
);

package main;

for ( '@d19.07.03 @704', '20030719T155345', 'gibberish' ) {
    print DateTime::Format::Fall->parse_datetime($_)->datetime, "\n";
}