/usr/share/perl5/HTML/Microformats/Format/hTodo.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 | =head1 NAME
HTML::Microformats::Format::hTodo - an hCalendar todo component
=head1 SYNOPSIS
use Data::Dumper;
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 $todo ($cal->get_vtodo)
{
printf("%s: %s\n", $todo->get_due, $todo->get_summary);
}
}
=head1 DESCRIPTION
HTML::Microformats::Format::hTodo is a helper module for HTML::Microformats::Format::hCalendar.
This class is used to represent todo components within calendars. Generally speaking,
you want to use HTML::Microformats::Format::hCalendar instead.
HTML::Microformats::Format::hTodo 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::hTodo;
use base qw(HTML::Microformats::Format HTML::Microformats::Mixin::Parser);
use common::sense;
use 5.010;
use HTML::Microformats::Utilities qw(stringify searchClass);
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Format::hTodo::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Format::hTodo::VERSION = '0.104';
}
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);
$self->_parse_related($clone);
$cache->set($context, $element, $class, $self)
if defined $cache;
return $self;
}
sub _parse_related
{
HTML::Microformats::Format::hEvent::_parse_related(@_);
}
sub extract_all
{
my ($class, $element, $context) = @_;
my @todos = HTML::Microformats::Format::extract_all($class, $element, $context);
foreach my $list (searchClass('vtodo-list', $element))
{
push @todos, $class->extract_all_xoxo($list, $context);
}
return @todos;
}
sub format_signature
{
my $ical = 'http://www.w3.org/2002/12/cal/icaltzd#';
my $icalx = 'http://buzzword.org.uk/rdf/icaltzdx#';
return {
'root' => 'vtodo',
'classes' => [
['attach', 'u*'],
['attendee', 'M*', {embedded=>'hCard !person', 'is-in-cal'=>1}],
['categories', '*'],
['category', '*', {'use-key'=>'categories'}],
['class', '?', {'value-title'=>'allow'}],
['comment', '*'],
['completed', 'd?'],
['contact', 'M*', {embedded=>'hCard !person', 'is-in-cal'=>1}],
['created', 'd?'],
['description', '?'],
#['dtend', 'd?'],
['dtstamp', 'd?'],
['dtstart', 'd1'],
['due', 'd?'],
['duration', 'D?'],
['exdate', 'd*'],
['exrule', 'e*'],
['geo', 'M*', {embedded=>'geo'}],
['last-modified', 'd?'],
['location', 'M*', {embedded=>'hCard adr geo'}],
['organizer', 'M*', {embedded=>'hCard !person', 'is-in-cal'=>1}],
['percent-complete', '?'],
['priority', '?', {'value-title'=>'allow'}],
['rdate', 'd*'],
['recurrance-id', 'U?'],
['resource', '*', {'use-key'=>'resources'}],
['resources', '*'],
['rrule', 'e*'],
['sequence', 'n?', {'value-title'=>'allow'}],
['status', '?', {'value-title'=>'allow'}],
['summary', '1'],
#['transp', '?'],
['uid', 'U?'],
['url', 'U?'],
['valarm', 'M*', {embedded=>'hAlarm'}],
['x-sighting-of', 'M*', {embedded=>'species'}] #extension
],
'options' => {
'rel-tag' => 'categories',
'rel-enclosure' => 'attach',
'hmeasure' => 'measures'
},
'rdf:type' => ["${ical}Vtodo"] ,
'rdf:property' => {
# 'attach' => { 'resource' => ["${ical}attach"] } ,
'attendee' => { 'resource' => ["${ical}attendee"], 'literal' => ["${icalx}attendee-literal"] } ,
'categories' => { 'resource' => ["${icalx}category"], 'literal' => ["${ical}category"] },
'class' => { 'literal' => ["${ical}class"] , 'literal_datatype' => 'string'} ,
'comment' => { 'literal' => ["${ical}comment"] } ,
'completed' => { 'literal' => ["${ical}completed"] } ,
'contact' => { 'resource' => ["${icalx}contact"], 'literal' => ["${ical}contact"] } ,
'created' => { 'literal' => ["${ical}created"] } ,
'description' => { 'literal' => ["${ical}description"] } ,
'dtend' => { 'literal' => ["${ical}dtend"] } ,
'dtstamp' => { 'literal' => ["${ical}dtstamp"] } ,
'dtstart' => { 'literal' => ["${ical}dtstart"] } ,
'due' => { 'literal' => ["${ical}due"] } ,
'duration' => { 'literal' => ["${ical}duration"] } ,
'exdate' => { 'literal' => ["${ical}exdate"] } ,
'geo' => { 'literal' => ["${icalx}geo"] } ,
'last-modified' => { 'literal' => ["${ical}lastModified"] } ,
'location' => { 'resource' => ["${icalx}location"], 'literal' => ["${ical}location"] } ,
'organizer' => { 'resource' => ["${ical}organizer"], 'literal' => ["${icalx}organizer-literal"] } ,
'percent-complete' => { 'literal' => ["${ical}percentComplete"] , 'literal_datatype' => 'integer' } ,
'priority' => { 'literal' => ["${ical}priority"] } ,
'rdate' => { 'literal' => ["${ical}rdate"] } ,
'recurrance-id' => { 'resource' => ["${ical}recurranceId"] , 'literal' => ["${ical}recurranceId"] , 'literal_datatype' => 'string' } ,
'resources' => { 'literal' => ["${ical}resources"] } ,
'sequence' => { 'literal' => ["${ical}sequence"] , 'literal_datatype' => 'integer' } ,
'status' => { 'literal' => ["${ical}status"] , 'literal_datatype' => 'string' } ,
'summary' => { 'literal' => ["${ical}summary"] } ,
'transp' => { 'literal' => ["${ical}transp"] , 'literal_datatype' => 'string' } ,
'uid' => { 'resource' => ["${ical}uid"] , 'literal' => ["${ical}uid"] , 'literal_datatype' => 'string' } ,
'url' => { 'resource' => ["${ical}url"] } ,
'valarm' => { 'resource' => ["${ical}valarm"] } ,
'x-sighting-of' => { 'resource' => ["${ical}x-sighting-of"] } ,
},
};
}
sub add_to_model
{
# essentially the same...
return HTML::Microformats::Format::hEvent::add_to_model(@_);
}
sub profiles
{
return HTML::Microformats::Format::hCalendar::profiles(@_);
}
sub extract_all_xoxo
{
my ($class, $element, $context) = @_;
return qw() unless $element->tagName =~ /^(ul|ol)$/i;
my @all_items;
foreach my $li ($element->getChildrenByTagName('li'))
{
my @these_items = $class->extract_all_xoxo_item($li, $context);
push @all_items, @these_items;
}
return @all_items;
}
sub extract_all_xoxo_item
{
my ($class, $element, $context) = @_;
return qw() unless $element->tagName eq 'li';
my $clone = $element->cloneNode(1);
# Find any child XOXO-style lists. Parse then discard.
my @child_items;
foreach my $list ($clone->getChildrenByTagName('ol'))
{
my @these_items = $class->extract_all_xoxo($list, $context);
push @child_items, @these_items;
$clone->removeChild($list);
}
foreach my $list ($clone->getChildrenByTagName('ul'))
{
my @these_items = $class->extract_all_xoxo($list, $context);
push @child_items, @these_items;
$clone->removeChild($list);
}
my $self = $class->new($clone, $context);
unless (length $self->data->{'summary'})
{
$self->data->{'summary'} = stringify($clone);
}
my @rv = ($self);
CHILD: foreach my $child (@child_items)
{
if (defined $child->{'related'}->{'parent'}
or defined $child->{'DATA'}->{'parent'})
{
push @{$child->{'related'}->{'other'}}, $self;
push @{$self->{'related'}->{'other'}}, $child;
}
else
{
$child->{'related'}->{'parent'} = $self;
push @{$self->{'related'}->{'child'}}, $child;
}
OTHERCHILD: foreach my $other_child (@child_items)
{
next OTHERCHILD if $child == $other_child;
push @{$child->{'related'}->{'sibling'}}, $other_child;
}
push @rv, $child;
}
return @rv;
}
sub to_icalendar
{
my ($self) = @_;
die "Need RDF::iCalendar to export iCalendar data.\n"
unless $HTML::Microformats::Format::hCalendar::HAS_ICAL_EXPORT;
my $exporter = RDF::iCalendar::Exporter->new;
return $exporter->export_component($self->model, $self->id(1))->to_string;
}
1;
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats::Format::hCalendar>,
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
|