/usr/share/perl5/HTML/Microformats/Datatype/RecurringDateTime.pm is in libhtml-microformats-perl 0.105-2+deb8u1.
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 | =head1 NAME
HTML::Microformats::Datatype::RecurringDateTime - a datetime that recurs
=head1 SYNOPSIS
my $r_datetime = HTML::Microformats::Datatype::RecurringDateTime->new($ical_string);
print "$r_datetime\n";
=cut
package HTML::Microformats::Datatype::RecurringDateTime;
use HTML::Microformats::Utilities qw(searchClass stringify);
use base qw(HTML::Microformats::Datatype);
use strict qw(subs vars); no warnings;
use 5.010;
use HTML::Microformats::Datatype::DateTime;
use RDF::Trine;
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Datatype::RecurringDateTime::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Datatype::RecurringDateTime::VERSION = '0.105';
}
=head1 DESCRIPTION
=head2 Constructors
=over 4
=item C<< $r = HTML::Microformats::Datatype::RecurringDateTime->new($string, [$context]) >>
Creates a new HTML::Microformats::Datatype::RecurringDateTime object.
$string is an iCalendar-RRULE-style string.
=cut
sub new
{
my $class = shift;
return $class->parse_string(@_) if @_;
bless {}, $class;
}
=item C<< $r = HTML::Microformats::Datatype::RecurringDateTime->parse($string, $elem, $context) >>
Creates a new HTML::Microformats::Datatype::RecurringDateTime object.
$string is perhaps an iCalendar-RRULE-style string. $elem is the
XML::LibXML::Element being parsed. $context is the document
context.
This constructor supports a number of experimental microformat
interval patterns. e.g.
<span class="rrule">
The summer lectures are held held <span class="freq">yearly</span>,
every <span class="interval">2</span>nd year (1999, 2001, etc),
every <span class="byday">Sunday</span>
in January <abbr class="bymonth" title="1" style="display:none"></abbr>
at <span class="byhour">8</span>:<span class="byminute">30</span> and
repeated at <span class="byhour">9</span>:30.
</span>
=cut
sub parse
{
my $class = shift;
my $string = shift;
my $elem = shift || undef;
my $context = shift || undef;
my $self = bless {}, $class;
$self->{'_context'} = $context;
$self->{'_id'} = $context->make_bnode;
my @freq_nodes = searchClass('freq', $elem);
unless (@freq_nodes)
{
if (lc $elem->tagName eq 'abbr' and $elem->hasAttribute('title'))
{ return $class->parse_string($elem->getAttribute('title'), $context); }
else
{ return $class->parse_string(''.stringify($elem, 'value'), $context); }
}
$self->{'freq'} = uc stringify($freq_nodes[0], 'value');
foreach my $n ($elem->getElementsByTagName('*'))
{
if ($n->getAttribute('class') =~ /\b (until|count) \b/x)
{
my $p = $1;
unless (defined $self->{'until'} || defined $self->{'count'})
{
$self->{$p} = ''.stringify($n, 'value');
$self->{$p} = HTML::Microformats::Datatype::DateTime->parse($self->{$p}, $elem, $context)
if $p eq 'until';
}
}
elsif ($n->getAttribute('class') =~ /\b (bysecond | byminute | byhour |
bymonthday | byyearday | byweekno | bymonth | bysetpos) \b/x)
{
my $p = $1;
my $v = stringify($n, 'value');
my @v = split ',', $v;
push @{ $self->{$p} }, @v;
}
elsif ($n->getAttribute('class') =~ /\b (byday | wkst) \b/x)
{
my $p = $1;
my $txt = stringify($n, 'value');
my @v = split ',', $txt;
foreach my $v (@v)
{
if ($v =~ /^\s*(\-?[12345])?\s*(MO|TU|WE|TH|FR|SA|SU)/i)
{ $v = uc($1.$2); }
else
{ $v = uc($txt); }
push @{ $self->{$p} }, "$v";
}
}
if ($n->getAttribute('class') =~ /\b interval \b/x)
{
my $v = stringify($n, 'value');
$self->{'interval'} = $v;
}
}
return $self;
}
=item C<< $r = HTML::Microformats::Datatype::RecurringDateTime->parse_string($string, [$context]) >>
Essentially just an alias for C<< new >>.
=back
=cut
sub parse_string
{
my $class = shift;
my $string = shift;
my $context = shift || undef;
my $self = bless {}, $class;
$self->{'_context'} = $context;
$self->{'_id'} = $context->make_bnode;
my @parts = split /\;/, $string;
foreach my $part (@parts)
{
my ($k,$v) = split /\=/, $part;
if ($k =~ /^( byday | wkst | bysecond | byminute | byhour |
bymonthday | byyearday | byweekno | bymonth | bysetpos )$/xi)
{
$self->{ lc $k } = [ split /\,/, $v ];
}
elsif ($k =~ /^( interval | until | count | freq )$/xi)
{
$self->{ lc $k } = uc $v;
}
}
return $self;
}
=head2 Public Methods
=over 4
=item C<< $r->to_string >>
Returns an iCal-RRULE-style formatted string representing the recurrance.
=cut
sub to_string
{
my $self = shift;
my $rv = '';
foreach my $p (qw(freq until count bysecond byminute byhour
bymonthday byyear byweekno bymonth bysetpos byday wkst interval))
{
if (ref $self->{$p} eq 'ARRAY')
{
$rv .= sprintf("%s=%s;", uc $p, (join ',', @{$self->{$p}}))
if @{$self->{$p}};
}
elsif (defined $self->{$p})
{
$rv .= sprintf("%s=%s;", uc $p, $self->{$p});
}
}
$rv =~ s/\;$//;
return $rv;
}
=item C<< $r->datatype >>
Returns an the RDF datatype URI representing the data type of this literal.
=cut
sub datatype
{
my $self = shift;
return 'http://buzzword.org.uk/rdf/icaltzdx#recur';
}
=item C<< $r->add_to_model($model) >>
Adds the recurring datetime to an RDF model as a resource (not a literal).
=back
=cut
sub add_to_model
{
my $self = shift;
my $model = shift;
my $me = RDF::Trine::Node::Blank->new( substr($self->{'_id'}, 2) );
my $ical = 'http://www.w3.org/2002/12/cal/icaltzd#';
foreach my $p (qw(freq until count bysecond byminute byhour
bymonthday byyear byweekno bymonth bysetpos byday wkst interval))
{
$model->add_statement(RDF::Trine::Statement->new(
$me,
RDF::Trine::Node::Resource->new("${ical}${p}"),
RDF::Trine::Node::Literal->new( (ref $self->{$p} eq 'ARRAY') ? (join ',', @{$self->{$p}}) : $self->{$p} ),
))
if defined $self->{$p};
}
$model->add_statement(RDF::Trine::Statement->new(
$me,
RDF::Trine::Node::Resource->new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
RDF::Trine::Node::Resource->new("http://buzzword.org.uk/rdf/icaltzdx#Recur"),
));
$model->add_statement(RDF::Trine::Statement->new(
$me,
RDF::Trine::Node::Resource->new("http://www.w3.org/1999/02/22-rdf-syntax-ns#value"),
RDF::Trine::Node::Literal->new($self->to_string, undef, $self->datatype),
));
return $self;
}
sub TO_JSON
{
my $self = shift;
return $self->to_string;
}
1;
__END__
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats>,
L<HTML::Microformats::Datatype>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
Copyright 2008-2012 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
|