root/zip2tz/generate_module.pl

Revision 2100 (checked in by miyagawa, 13 years ago)

import zip2tz

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use YAML;
5
6 my $state2tz  = YAML::LoadFile($ARGV[0]);
7
8 use Data::Dumper;
9 $Data::Dumper::Indent = 1;
10 $Data::Dumper::Terse  = 1;
11
12 my $module = <<'MODULE';
13 package DateTime::TimeZone::FromState::US;
14 use strict;
15 use Carp;
16 use DateTime::TimeZone;
17
18 our $state2tz  = __S2T__;
19
20 sub new_from_state {
21     my($class, %p) = @_;
22
23     my $state = $p{state}            or croak 'new_from_state: state is empty';
24        $state =~ /^[A-Za-z]{2}$/     or croak "new_from_state: needs 2 letters State name: $state";
25     my $tz = $state2tz->{uc($state)} or croak "Data error: TZ for $state is unknown";
26
27     DateTime::TimeZone->new(name => $tz);
28 }
29
30 1;
31 MODULE
32
33 $module =~ s/__S2T__/Dumper($state2tz)/e;
34
35 print $module;
36
37
Note: See TracBrowser for help on using the browser.