line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
6
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
1242
|
use Net::Domain qw(hostfqdn); |
|
1
|
|
|
|
|
13825
|
|
|
1
|
|
|
|
|
90
|
|
30
|
1
|
|
|
1
|
|
1126
|
use Date::ICal; |
|
1
|
|
|
|
|
16768
|
|
|
1
|
|
|
|
|
13
|
|
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
|
0
|
|
|
0
|
1
|
0
|
my ($time) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
0
|
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
|
0
|
|
|
|
|
0
|
$time = Date::ICal->new (epoch => time); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#quick internals hack into Date::ICal to force UTC time instead |
77
|
0
|
|
|
|
|
0
|
$time->{timezone} = "UTC"; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# using Net::Domain to get a fqdn |
80
|
0
|
|
|
|
|
0
|
my $host = &hostfqdn; |
81
|
0
|
|
|
|
|
0
|
chomp $host; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
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
|
9
|
|
|
9
|
1
|
21
|
my ($obj, $str) = @_; |
107
|
9
|
|
|
|
|
16
|
my $err; |
108
|
|
|
|
|
|
|
|
109
|
9
|
|
|
|
|
16
|
my $domain = caller; |
110
|
9
|
|
|
|
|
50
|
$domain =~ s/(.*)::\w+/$1/; |
111
|
9
|
|
|
|
|
79
|
$err = "[$domain] " . $obj->type; |
112
|
|
|
|
|
|
|
#if (UNIVERSAL::can ($obj, 'uid')) { |
113
|
|
|
|
|
|
|
#if ($obj->uid) { |
114
|
|
|
|
|
|
|
# $err .= " (" . $obj->uid . ")"; |
115
|
|
|
|
|
|
|
# } |
116
|
9
|
|
|
|
|
256
|
$err .= ": $str"; |
117
|
9
|
|
|
|
|
12
|
push (@{$obj->errlog}, $err); |
|
9
|
|
|
|
|
50
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
More documentation pointers can be found in L. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |