TimeZone.pm

filter: Statementstmt 100% 32 / 32 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 97.8% 45 / 46 CC 4 SCAR 7.9
CC
4
Cov
97%
new
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
↑ Summary ._TimeZone.pm »
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<error_message>.
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<timezone> argument to ->new
52  
53 =item No such timezone '%s'
54  
55 The C<timezone> 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 <richardc@unixbeard.net>
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<perlartistic>.
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<Data::ICal::TimeZone::Object>, L<Data::ICal>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 2 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 2 ▶use Class::ReturnValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 2 ▶use Data::ICal::TimeZone::List qw( zones );
Subroutine BEGIN: called CC=1 SCAR=0.0
96 2 our $VERSION = 1.23;
97  
98 2 ▶sub _error {
Subroutine _error: called CC=1 SCAR=0.0
99 2 my $class = shift;
100 2 my $msg = shift;
101  
102 2 my $ret = Class::ReturnValue->new;
103 2 $ret->as_error( errno => 1, message => $msg );
104 2 return $ret;
105 }
106  
107 400 ▶sub _zone_package {
Subroutine _zone_package: called CC=1 SCAR=0.0
108 400 my $class = shift;
109 400 my $zone = shift;
110 400 $zone =~ s{-}{_}g;
111 400 $zone =~ s{/}{::}g;
112 400 return __PACKAGE__."::Object::$zone";
113 }
114  
115 402 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
116 402 my $class = shift;
117 402 my %args = @_;
118 my $timezone = delete $args{timezone}
119 402 ▶ or return $class->_error( "No timezone specified" );
Branch: 1 branch
BranchTrueFalseTotal
my $timezone = delete $args{"timezone"} or return $class->_error("No timezone specified") 401 1 402
120 401 ▶ grep { $_ eq $timezone } $class->zones
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ eq $timezone;} $class->zones or return $class->_error("No such timezone '${timezone}'") 400 1 401
121 or return $class->_error( "No such timezone '$timezone'" );
122 400 my $tz = $class->_zone_package( $timezone );
123 400 ▶ $tz->require
Branch: 1 branch
BranchTrueFalseTotal
$tz->require or return $class->_error("Couldn't require ${tz}: $@") 400 0 400
124 or return $class->_error( "Couldn't require $tz: $@" );
125 400 return $tz->new;
126 }
127  
128 2 1;
↑ Summary ._TimeZone.pm »