line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
39025
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
119
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package ICal::Format::Natural; |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$ICal::Format::Natural::VERSION = '1.121310'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Create an Data::ICal object with natural parsing logic. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(ical_format_natural); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
1039
|
use Data::ICal; |
|
1
|
|
|
|
|
52184
|
|
|
1
|
|
|
|
|
11
|
|
16
|
1
|
|
|
1
|
|
881
|
use Data::ICal::Entry::Event; |
|
1
|
|
|
|
|
333
|
|
|
1
|
|
|
|
|
8
|
|
17
|
1
|
|
|
1
|
|
997
|
use DateTime::Format::Natural; |
|
1
|
|
|
|
|
261856
|
|
|
1
|
|
|
|
|
80
|
|
18
|
1
|
|
|
1
|
|
926
|
use DateTime::Format::ICal; |
|
1
|
|
|
|
|
65303
|
|
|
1
|
|
|
|
|
266
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub ical_format_natural { |
22
|
4
|
|
|
4
|
1
|
2378
|
my $in = shift; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
17
|
my ( $date, $summary ) = split '\.', $in; |
25
|
4
|
|
50
|
|
|
13
|
$date ||= ''; |
26
|
4
|
|
100
|
|
|
19
|
$summary ||= ''; |
27
|
4
|
|
|
|
|
9
|
chomp $date; |
28
|
4
|
|
|
|
|
6
|
chomp $summary; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# trim leading and trailing whitespace |
31
|
4
|
|
|
|
|
19
|
$summary =~ s/^\s+|\s+$//g; |
32
|
|
|
|
|
|
|
|
33
|
4
|
100
|
|
|
|
17
|
return 'error: no summary' unless $summary; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# parse date |
36
|
2
|
|
|
|
|
20
|
my $parser = DateTime::Format::Natural->new; |
37
|
2
|
|
|
|
|
53075
|
my $dt = $parser->parse_datetime($date); |
38
|
|
|
|
|
|
|
|
39
|
2
|
100
|
|
|
|
24080
|
if ( $parser->success ) { |
40
|
1
|
|
|
|
|
41
|
my $calendar = Data::ICal->new; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
450
|
my $vevent = Data::ICal::Entry::Event->new; |
43
|
1
|
|
|
|
|
44
|
$vevent->add_properties( |
44
|
|
|
|
|
|
|
summary => $summary, |
45
|
|
|
|
|
|
|
dtstart => DateTime::Format::ICal->format_datetime($dt), |
46
|
|
|
|
|
|
|
dtend => |
47
|
|
|
|
|
|
|
DateTime::Format::ICal->format_datetime( $dt->add( hours => 1 ) ), |
48
|
|
|
|
|
|
|
); |
49
|
1
|
|
|
|
|
1395
|
$calendar->add_entry($vevent); |
50
|
1
|
|
|
|
|
24
|
$calendar->add_properties( method => 'PUBLISH' ); |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
177
|
return $calendar; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return |
56
|
1
|
|
|
|
|
30
|
sprintf( "error parsing date (%s). error was: %s", $date, |
57
|
|
|
|
|
|
|
$parser->error ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |