ICal/Util.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.5
CC
2
Cov
0%
create_uuid
6.0
add_validation_error
2.0
BEGIN
2.0
CRAP 3.1
1 #!/usr/bin/perl -w
2 # vi:sts=4:shiftwidth=4
3 # -*- Mode: perl -*-
4 #======================================================================
5 #
6 # This package is free software and is provided "as is" without
7 # express or implied warranty. It may be used, redistributed and/or
8 # modified under the same terms as perl itself. ( Either the Artistic
9 # License or the GPL. )
10 #
11 # $Id: Util.pm,v 1.4 2001/08/04 04:59:36 srl Exp $
12 #
13 # (C) COPYRIGHT 2000-2001, Reefknot developers.
14 #
15 # See the AUTHORS file included in the distribution for a full list.
16 #======================================================================
17  
18 =head1 NAME
19  
20 Net::ICal::Util -- Utility functions for Net::ICal modules
21  
22 =cut
23  
24 package Net::ICal::Util;
25 use strict;
26  
27 use base qw(Exporter);
28  
29 use Net::Domain qw(hostfqdn);
30 use Date::ICal;
31  
32 our %EXPORT_TAGS = (
33 all => [qw(
34 create_uuid
35 add_validation_error
36 )],
37 );
38  
39 our @EXPORT = ();
40 our @EXPORT_OK = qw(
41 create_uuid
42 add_validation_error
43 );
44  
45 =head1 DESCRIPTION
46  
47 General utility functions for Net::ICal and friends
48  
49 =head1 FUNCTIONS
50  
51 =head2 create_uuid
52  
53 Generate a globally unique ID.
54  
55 =begin testing
56 use Net::ICal::Util;
57  
58 my $uuid = create_uuid;
59  
60 ok(defined($uuid), "create_uuid with no arguments returns a value");
61  
62 =end
63  
64 =cut
65  
66 my $count = 0;
67 sub create_uuid {
68 my ($time) = @_;
69  
70 unless (defined $time) {
71 #what we really want, but Date::ICal can't handle that yet
72 #$time = Date::ICal->new (epoch => time, timezone => 'UTC');
73 $time = Date::ICal->new (epoch => time);
74 }
75  
76 #quick internals hack into Date::ICal to force UTC time instead
77 $time->{timezone} = "UTC";
78  
79 # using Net::Domain to get a fqdn
80 my $host = &hostfqdn;
81 chomp $host;
82  
83 return $time->ical # time with second precision
84 . "-$$-" # plus process id
85 . $count++ # plus counter
86 . "\@$host"; # plus fqdn should be sufficiently unique
87 }
88  
89  
90 =head2 add_validation_error ($object, $string)
91  
92 Add a validation error containing $string to the errlog list of
93 $object
94  
95 =begin testing
96  
97 TODO: {
98 local $TODO = "write tests for add_validation_error";
99 };
100  
101 =end testing
102  
103 =cut
104  
105 sub add_validation_error {
106 my ($obj, $str) = @_;
107 my $err;
108  
109 my $domain = caller;
110 $domain =~ s/(.*)::\w+/$1/;
111 $err = "[$domain] " . $obj->type;
112 #if (UNIVERSAL::can ($obj, 'uid')) {
113 #if ($obj->uid) {
114 # $err .= " (" . $obj->uid . ")";
115 # }
116 $err .= ": $str";
117 push (@{$obj->errlog}, $err);
118 }
119  
120 1;
121  
122 =head1 SEE ALSO
123  
124 More documentation pointers can be found in L<Net::ICal>.
125  
126 =cut