/usr/share/perl5/HTML/Microformats/Format/hCalendar.pm is in libhtml-microformats-perl 0.104-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | =head1 NAME
HTML::Microformats::Format::hCalendar - the hCalendar microformat
=head1 SYNOPSIS
use HTML::Microformats::DocumentContext;
use HTML::Microformats::Format::hCalendar;
my $context = HTML::Microformats::DocumentContext->new($dom, $uri);
my @cals = HTML::Microformats::Format::hCalendar->extract_all(
$dom->documentElement, $context);
foreach my $cal (@cals)
{
foreach my $event ($cal->get_vevent)
{
printf("%s: %s\n", $ev->get_dtstart, $ev->get_summary);
}
}
=head1 DESCRIPTION
HTML::Microformats::Format::hCalendar inherits from HTML::Microformats::Format. See the
base class definition for a description of property getter/setter methods,
constructors, etc.
=head2 Additional Method
=over
=item * C<< to_icalendar >>
This method exports the data in iCalendar format. It requires
L<RDF::iCalendar> to work, and will throw an error at run-time
if it's not available.
=back
=cut
package HTML::Microformats::Format::hCalendar;
use base qw(HTML::Microformats::Format HTML::Microformats::Mixin::Parser);
use common::sense;
use 5.010;
use HTML::Microformats::Utilities qw(searchClass searchAncestorClass);
use HTML::Microformats::Format::hEntry;
use HTML::Microformats::Format::hEvent;
use HTML::Microformats::Format::hTodo;
use HTML::Microformats::Format::hAlarm;
use HTML::Microformats::Format::hFreebusy;
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Format::hCalendar::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Format::hCalendar::VERSION = '0.104';
}
our $HAS_ICAL_EXPORT;
BEGIN
{
local $@ = undef;
eval 'use RDF::iCalendar;';
$HAS_ICAL_EXPORT = 1
if RDF::iCalendar::Exporter->can('new');
}
sub new
{
my ($class, $element, $context) = @_;
my $cache = $context->cache;
return $cache->get($context, $element, $class)
if defined $cache && $cache->get($context, $element, $class);
my $self = {
'element' => $element ,
'context' => $context ,
'cache' => $cache ,
'id' => $context->make_bnode($element) ,
};
bless $self, $class;
my $clone = $element->cloneNode(1);
$self->_expand_patterns($clone);
$self->_simple_parse($clone);
foreach my $todolist (searchClass('vtodo-list', $element))
{
my $holder_calendar = searchAncestorClass('vcalendar', $todolist);
if (!defined $holder_calendar or
$element->getAttribute('data-cpan-html-microformats-nodepath') eq $holder_calendar->getAttribute('data-cpan-html-microformats-nodepath'))
{
push @{$self->{'DATA'}->{'vtodo'}},
HTML::Microformats::Format::hTodo->extract_all_xoxo($todolist, $context);
}
}
$self->_calculate_relationships;
$self->_cement_relationships;
$cache->set($context, $element, $class, $self)
if defined $cache;
return $self;
}
sub _calculate_relationships
{
my $self = shift;
my %xpath;
foreach my $component (qw(vevent vtodo vjournal))
{
foreach my $object (@{ $self->data->{$component} })
{
my $xp = $object->element->getAttribute('data-cpan-html-microformats-nodepath');
$xpath{$xp} = $object;
}
}
my @xpaths = keys %xpath;
foreach my $xp (@xpaths)
{
unless (defined $xpath{$xp}->{'related'}->{'parent'}
or defined $xpath{$xp}->data->{'parent'})
{
my $parent = __findParent($xp, @xpaths);
if ($parent)
{
$xpath{$xp}->{'related'}->{'parent'} = $xpath{$parent};
push @{ $xpath{$parent}->{'related'}->{'child'} }, $xpath{$xp};
}
}
}
}
sub __findParent
{
my $x = shift;
my $longest = '';
foreach my $potential (@_)
{
if (__ancestorOf($potential, $x))
{
$longest = $potential
if (length($potential) > length($longest));
}
}
return $longest;
}
sub __ancestorOf
{
my ($a, $b) = @_;
return if ($a eq $b);
return (substr($b, 0, length($a)) eq $a);
}
sub _cement_relationships
{
my $self = shift;
my @objects;
foreach my $component (qw(vevent vtodo vjournal))
{
push @objects, @{ $self->data->{$component} };
}
foreach my $object (@objects)
{
# Share parent data between $obj->{'DATA'} and $obj->{'related'}.
if (defined $object->{'related'}->{'parent'}
and !defined $object->{'DATA'}->{'parent'})
{
$object->{'DATA'}->{'parent'} = $object->{'related'}->{'parent'}->get_uid;
}
elsif (!defined $object->{'related'}->{'parent'}
and defined $object->{'DATA'}->{'parent'})
{
$object->{'related'}->{'parent'} =
grep {$_->get_uid eq $object->{'DATA'}->{'parent'}} @objects;
}
# Share other data similarly.
foreach my $relationship (qw(sibling other child))
{
foreach my $related (@{ $object->{'related'}->{$relationship} })
{
next unless defined $related->get_uid;
push @{$object->{'DATA'}->{$relationship}},
$related->get_uid
unless grep { $_ eq $related->get_uid } @{$object->{'DATA'}->{$relationship}};
$object->{'DATA'}->{$relationship} = undef
unless @{ $object->{'DATA'}->{$relationship} };
}
foreach my $related (@{ $object->{'DATA'}->{$relationship} })
{
push @{$object->{'related'}->{$relationship}},
(grep { $_->get_uid eq $related } @objects);
$object->{'related'}->{$relationship} = undef
unless @{$object->{'related'}->{$relationship}};
}
}
}
return $self;
}
sub extract_all
{
my ($class, $element, $context) = @_;
my @cals = HTML::Microformats::Format::extract_all($class, $element, $context);
if ($element->tagName eq 'html' || !@cals)
{
my @components = HTML::Microformats::Format::hEvent->extract_all($element, $context);
push @components, HTML::Microformats::Format::hTodo->extract_all($element, $context);
push @components, HTML::Microformats::Format::hFreebusy->extract_all($element, $context);
push @components, HTML::Microformats::Format::hEntry->extract_all($element, $context);
my $orphans = 0;
foreach my $c (@components)
{
$orphans++ unless searchAncestorClass('hcalendar', $c->element);
}
if ($orphans)
{
my $slurpy = $class->new($element, $context);
unshift @cals, $slurpy;
}
}
return @cals;
}
sub format_signature
{
my $ical = 'http://www.w3.org/2002/12/cal/icaltzd#';
return {
'root' => 'vcalendar',
'classes' => [
['vevent', 'M*', {embedded=>'hEvent'}],
['vtodo', 'M*', {embedded=>'hTodo'}],
['hentry', 'M*', {embedded=>'hEntry', 'use-key'=>'vjournal'}],
['vfreebusy', 'M*', {embedded=>'hFreebusy'}],
['calscale', '?'],
['method', '?'],
],
'options' => {
},
'rdf:type' => ["${ical}Vcalendar"] ,
'rdf:property' => {
'vevent' => { 'resource' => ["${ical}component"] } ,
'vtodo' => { 'resource' => ["${ical}component"] } ,
'vfreebusy' => { 'resource' => ["${ical}component"] } ,
'vjournal' => { 'resource' => ["${ical}component"] } ,
'calscale' => { 'literal' => ["${ical}calscale"] , 'literal_datatype' => 'string'} ,
'method' => { 'literal' => ["${ical}method"] , 'literal_datatype' => 'string'} ,
},
};
}
sub add_to_model
{
my $self = shift;
my $model = shift;
$self->_simple_rdf($model);
foreach my $journal (@{ $self->data->{vjournal} })
{
$journal->add_to_model_ical($model);
}
return $self;
}
sub profiles
{
return qw(http://purl.org/uF/hCalendar/1.1/
http://microformats.org/profile/hcalendar
http://ufs.cc/x/hcalendar
http://microformats.org/profile/specs
http://ufs.cc/x/specs
http://dannyayers.com/microformats/hcalendar-profile
http://www.w3.org/2002/12/cal/hcal
http://purl.org/uF/hCalendar/1.0/
http://purl.org/uF/2008/03/);
}
sub to_icalendar
{
my ($self) = @_;
die "Need RDF::iCalendar to export iCalendar data.\n" unless $HAS_ICAL_EXPORT;
my $exporter = RDF::iCalendar::Exporter->new;
return $exporter->export_calendar($self->model, $self->id(1))->to_string;
}
1;
=head1 MICROFORMAT
HTML::Microformats::Format::hCalendar supports hCalendar as described at
L<http://microformats.org/wiki/User:TobyInk/hcalendar-1.1>.
=head1 RDF OUTPUT
Data is returned using the W3C's revised iCalendar vocabulary
(L<http://www.w3.org/2002/12/cal/icaltzd#>) with some supplemental
terms from Toby Inkster's revised iCalendar extensions vocabulary
(L<http://buzzword.org.uk/rdf/icaltzdx#>) and occasional other terms.
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats::Format>,
L<HTML::Microformats>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT
Copyright 2008-2011 Toby Inkster
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
|