| 1 | package OurCal::View::ICalendar; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use Data::ICal::DateTime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use Data::ICal::Entry::Event; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use HTTP::Date; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use DateTime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 2 | ▶ | use Text::Chump; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use CGI qw(:standard); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use URI::Find::Simple qw(list_uris); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | =head1 NAME | ||||||||||||
| 16 | |||||||||||||
| 17 | OurCal::View::ICalendar - an ICalendar view | ||||||||||||
| 18 | |||||||||||||
| 19 | =head1 METHODS | ||||||||||||
| 20 | |||||||||||||
| 21 | =cut | ||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | =head2 new <param[s]> | ||||||||||||
| 25 | |||||||||||||
| 26 | =cut | ||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 29 | 0 | my ($class, %what) = @_; | |||||||||||
| 30 | 0 | return bless \%what, $class; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | =head2 mime_type | ||||||||||||
| 34 | |||||||||||||
| 35 | Returns the mime type of this view - 'text/calendar' | ||||||||||||
| 36 | |||||||||||||
| 37 | =cut | ||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | sub mime_type { | ||||||||||
|
Subroutine
mime_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 40 | 0 | return "text/calendar"; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | =head2 handle <param[s]> | ||||||||||||
| 44 | |||||||||||||
| 45 | Returns a string of ICalendar representing events and todo items. | ||||||||||||
| 46 | |||||||||||||
| 47 | Can optionally take a limit param which describes the number of events | ||||||||||||
| 48 | to have. Defaults to 50. | ||||||||||||
| 49 | |||||||||||||
| 50 | =cut | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub handle { | ||||||||||
|
Subroutine
handle: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||
| 54 | 0 | my %opts = @_; | |||||||||||
| 55 | 0 | ▶ | $opts{limit} ||= 50; | ||||||||||
|
Condition0%0/2
$opts{"limit"} ||= 50
MC/DC0%0/1
$opts{"limit"} ||= 50
$opts{"limit"}
Truth table0%0/2
A
A= $opts{"limit"}
| |||||||||||||
| 56 | |||||||||||||
| 57 | 0 | my $tc = Text::Chump->new; | |||||||||||
| 58 | 0 | ▶ | $tc->install('link', sub { return "$_[2] ($_[1])" }); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 59 | |||||||||||||
| 60 | 0 | my @events = $self->{calendar}->events(%opts); | |||||||||||
| 61 | 0 | my $cal = Data::ICal->new(); | |||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | 0 | foreach my $item (@events) { | |||||||||||
| 65 | 0 | my $event = Data::ICal::Entry::Event->new; | |||||||||||
| 66 | 0 | my $date = $self->_make_date($item->date); | |||||||||||
| 67 | 0 | my $uid = md5_hex($date.$item->description); | |||||||||||
| 68 | 0 | my $desc = $tc->chump($item->description); | |||||||||||
| 69 | 0 | my ($url) = list_uris($desc); | |||||||||||
| 70 | |||||||||||||
| 71 | # uid | ||||||||||||
| 72 | 0 | $event->uid( $uid ); | |||||||||||
| 73 | # start | ||||||||||||
| 74 | 0 | $event->start($date); | |||||||||||
| 75 | # summary | ||||||||||||
| 76 | 0 | $event->summary($desc); | |||||||||||
| 77 | # description | ||||||||||||
| 78 | 0 | $event->description($desc); | |||||||||||
| 79 | # url | ||||||||||||
| 80 | 0 | ▶ | $event->add_property( url => $url ) if defined $url; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | |||||||||||||
| 82 | 0 | $cal->add_entry($event); | |||||||||||
| 83 | } | ||||||||||||
| 84 | 0 | return $cal->as_string; | |||||||||||
| 85 | |||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 0 | ▶ | sub _make_date { | ||||||||||
|
Subroutine
_make_date: not called CC=1 SCAR=6.9
| |||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||
| 90 | 0 | my $date = shift; | |||||||||||
| 91 | 0 | my ($y, $m, $d) = split /-/, $date; | |||||||||||
| 92 | 0 | return DateTime->new( year => $y, month => $m, day => $d); | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | 2 | 1; | |||||||||||