1use strict;
2
3use Test::More tests => 3;
4
5use DateTime::Format::Builder;
6
7
8{
9    my $sample = 'SampleClassWithSelf';
10    DateTime::Format::Builder->create_class(
11	class	 => $sample,
12	parsers    => {
13	    parse_datetime => [    
14	    [
15		preprocess => sub {
16		    my %p = @_;
17		    my $self = $p{self};
18		    $p{parsed}->{time_zone} = $self->{global}
19			if $self->{global};
20		    return $p{input};
21		},
22	    ],
23	    {
24		params => [ qw( year month day hour minute second ) ],
25		regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
26		preprocess =>  sub {
27		    my %p = @_;
28		    my $self = $p{self};
29		    $p{parsed}->{time_zone} = $self->{pre}
30			if $self->{pre}; 
31		    return $p{input};
32		},
33		postprocess => sub {
34		    my %p = @_;
35		    my $self = $p{self};
36		    $p{parsed}->{time_zone} = $self->{post}
37			if $self->{post}; 
38		    return 1;
39		},
40	    },
41	    ],
42	}
43    );
44
45    my %tests = (
46	global => 'Africa/Cairo',
47	pre	=> 'Europe/London',
48	post	=> 'Australia/Sydney',
49    );
50
51    while ( my ($callback, $value) = each %tests )
52    {
53	my $parser = $sample->new();
54	$parser->{$callback} = $value;
55	my $dt = $parser->parse_datetime( "20030716T163245" );
56	is( $dt->time_zone->name, $value );
57    }
58}
59