File Coverage

blib/lib/Data/ICal/TimeZone.pm
Criterion Covered Total %
statement 30 30 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 43 44 97.7


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Data::ICal::TimeZone - timezones for Data::ICal
4              
5             =head1 SYNOPSIS
6              
7             use Data::ICal;
8             use Data::ICal::TimeZone;
9              
10             my $cal = Data::ICal->new;
11             my $zone = Data::ICal::TimeZone->new( timezone => 'Europe/London' );
12             $cal->add_event( $zone->definition );
13             my $event = Data::ICal::Entry::Event->new;
14             $event->add_properties(
15             summary => 'Go to the pub',
16             dtstart => [ '20070316T180000' , { TZID => $zone->timezone } ],
17             dtend => [ '20070316T230000' , { TZID => $zone->timezone } ],
18             );
19             $cal->add_event( $event );
20              
21             =head1 DESCRIPTION
22              
23             Data::ICal::TimeZone provides a mechanism for adding the Olsen
24             standard timezones to your ical documents, plus a copy of the Olsen
25             timezone database.
26              
27             =head1 METHODS
28              
29             =over
30              
31             =item new( timezone => 'zone_name' )
32              
33             Returns a timezone object, this will be a Data::ICal::TimeZone::Object
34              
35             Returns a false value upon failure to locate the specified timezone or
36             load it's data class; this false value is a Class::ReturnValue object
37             and can be queried as to its C.
38              
39             =item zones
40              
41             Returns the a list of the supported timezones
42              
43             =back
44              
45             =head1 DIAGNOSTICS
46              
47             =over
48              
49             =item No timezone specified
50              
51             You failed to specify a C argument to ->new
52              
53             =item No such timezone '%s'
54              
55             The C you specifed to ->new wasn't one this module knows of.
56              
57             =item Couldn't require Data::ICal::TimeZone::Object::%s: %s
58              
59             The underlying class didn't compile cleanly.
60              
61             =back
62              
63              
64             =head1 AUTHOR
65              
66             Richard Clamp
67              
68             =head1 LICENCE AND COPYRIGHT
69              
70             Copyright 2007, Richard Clamp. All rights reserved.
71              
72             This module is free software; you can redistribute it and/or modify it
73             under the same terms as Perl itself. See L.
74              
75             =head1 BUGS
76              
77             None currently known, please report any you find to the author.
78              
79             =head1 VERSION
80              
81             The current zone data was generated from tzdata2007g using Vzic 1.3.
82              
83             =head1 SEE ALSO
84              
85             L, L
86              
87             http://dialspace.dial.pipex.com/prod/dialspace/town/pipexdsl/s/asbm26/vzic/
88              
89             =cut
90              
91             package Data::ICal::TimeZone;
92 2     2   1364 use strict;
  2         4  
  2         67  
93 2     2   1580 use UNIVERSAL::require;
  2         3202  
  2         20  
94 2     2   1622 use Class::ReturnValue;
  2         32523  
  2         260  
95 2     2   1492 use Data::ICal::TimeZone::List qw( zones );
  2         6  
  2         705  
96             our $VERSION = 1.23;
97              
98             sub _error {
99 2     2   4 my $class = shift;
100 2         2 my $msg = shift;
101              
102 2         8 my $ret = Class::ReturnValue->new;
103 2         12 $ret->as_error( errno => 1, message => $msg );
104 2         1033 return $ret;
105             }
106              
107             sub _zone_package {
108 400     400   845 my $class = shift;
109 400         719 my $zone = shift;
110 400         1306 $zone =~ s{-}{_}g;
111 400         1652 $zone =~ s{/}{::}g;
112 400         1561 return __PACKAGE__."::Object::$zone";
113             }
114              
115             sub new {
116 402     402 1 222733 my $class = shift;
117 402         1270 my %args = @_;
118 402 100       1921 my $timezone = delete $args{timezone}
119             or return $class->_error( "No timezone specified" );
120 401 100       2028 grep { $_ eq $timezone } $class->zones
  159999         199562  
121             or return $class->_error( "No such timezone '$timezone'" );
122 400         6994 my $tz = $class->_zone_package( $timezone );
123 400 50       4379 $tz->require
124             or return $class->_error( "Couldn't require $tz: $@" );
125 400         10510 return $tz->new;
126             }
127              
128             1;