/usr/share/perl5/HTML/Microformats/Datatype/Interval.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 307 308 309 310 311 312 313 314 315 316 317 | =head1 NAME
HTML::Microformats::Datatype::Interval - concrete periods of time
=head1 SYNOPSIS
my $interval = HTML::Microformats::Datatype::Interval->new($span);
print "$interval\n";
=cut
package HTML::Microformats::Datatype::Interval;
use overload '""'=>\&to_string, '<=>'=>\&compare, 'cmp'=>\&compare;
use strict qw(subs vars); no warnings;
use base qw(Exporter HTML::Microformats::Datatype);
our @EXPORT = qw();
our @EXPORT_OK = qw(compare);
use DateTime::Span;
use HTML::Microformats::Utilities qw(stringify searchClass);
use HTML::Microformats::Datatype::Duration;
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Datatype::Interval::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Datatype::Interval::VERSION = '0.105';
}
=head1 DESCRIPTION
=head2 Constructors
=over 4
=item C<< $i = HTML::Microformats::Datatype::Interval->new($span) >>
Creates a new HTML::Microformats::Datatype::Interval object.
$span is a DateTime::Span object.
=cut
sub new
{
my $class = shift;
my $interval_obj = shift;
my $this = {};
$this->{i} = $interval_obj;
bless $this, $class;
return $this;
}
=item C<< $i = HTML::Microformats::Datatype::Interval->parse($string, $elem, $context) >>
Creates a new HTML::Microformats::Datatype::Interval object.
$string is an interval represented in ISO 8601 format, for example:
'2010-01-01/P1Y' or '2010-01-01/2011-01-01'. $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.
<div class="interval">
<span class="d">4</span> days starting from
<abbr class="start" title="2010-01-01">2010</abbr>
</div>
=back
=cut
sub parse
{
my $class = shift;
my $string = shift;
my $elem = shift||undef;
my $page = shift||undef;
my $rv = {};
if ($string =~ /^ \s* (.+) \s* \/ \s* (.+) \s* $/x)
{
my $one = $1;
my $two = $2;
if ($one =~ /^P/i && $two !~ /^P/i)
{
my $duration = HTML::Microformats::Datatype::Duration->parse($one, $elem, $page);
my $before = HTML::Microformats::Datatype::DateTime->parse($two, $elem, $page);
if ($duration && $before)
{
my $span = DateTime::Span->from_datetime_and_duration(
duration => $duration->{d},
before => $before
);
$rv->{i} = $span if ($span);
}
}
elsif ($one !~ /^P/i && $two !~ /^P/i)
{
my $start = HTML::Microformats::Datatype::DateTime->parse($one, $elem, $page);
my $before = HTML::Microformats::Datatype::DateTime->parse($two, $elem, $page, undef, $start);
if ($start && $before)
{
my $span = DateTime::Span->from_datetimes(
start => $start,
before => $before
);
$rv->{i} = $span if ($span);
}
}
elsif ($one !~ /^P/i && $two =~ /^P/i)
{
my $start = HTML::Microformats::Datatype::DateTime->parse($one, $elem, $page);
my $duration = HTML::Microformats::Datatype::Duration->parse($two, $elem, $page);
if ($duration && $start)
{
my $span = DateTime::Span->from_datetime_and_duration(
duration => $duration->{d},
start => $start
);
$rv->{i} = $span if ($span);
}
}
}
if (! $rv->{i})
{
my $duration = HTML::Microformats::Datatype::Duration->parse(undef, $elem, $page);
my $time = {};
PROP: foreach my $prop (qw(start after))
{
my @nodes = searchClass($prop, $elem);
NODE: foreach my $n (@nodes)
{
$time->{$prop} = HTML::Microformats::Datatype::DateTime->parse(
stringify($nodes[0], undef, 1), $nodes[0], $page);
last NODE if ($time->{$prop});
}
}
PROP: foreach my $prop (qw(end before))
{
my @nodes = searchClass($prop, $elem);
NODE: foreach my $n (@nodes)
{
$time->{$prop} = HTML::Microformats::Datatype::DateTime->parse(
stringify($nodes[0], undef, 1), $nodes[0], $page, undef, ($time->{start} || $time->{after})
);
last NODE if ($time->{$prop});
}
}
if (($time->{start}||$time->{after})
&& ($time->{end}||$time->{before}))
{
my $startlabel = ($time->{start}) ? 'start' : 'after';
my $endlabel = ($time->{end}) ? 'end' : 'before';
my $span = DateTime::Span->from_datetimes(
$startlabel => ($time->{start}||$time->{after}),
$endlabel => ($time->{end}||$time->{before})
);
$rv->{i} = $span if ($span);
}
elsif (($time->{start}||$time->{after})
&& ($duration))
{
my $startlabel = ($time->{start}) ? 'start' : 'after';
my $span = DateTime::Span->from_datetime_and_duration(
$startlabel => ($time->{start}||$time->{after}),
duration => $duration->{d}
);
$rv->{i} = $span if ($span);
}
elsif (($duration)
&& ($time->{end}||$time->{before}))
{
my $endlabel = ($time->{end}) ? 'end' : 'before';
my $span = DateTime::Span->from_datetime_and_duration(
duration => $duration->{d},
$endlabel => ($time->{end}||$time->{before})
);
$rv->{i} = $span if ($span);
}
}
if ($rv->{i})
{
$rv->{string} = $string;
bless $rv, $class;
return $rv;
}
return undef;
}
=head2 Public Methods
=over 4
=item C<< $span = $i->span >>
Returns a DateTime::Span object.
=cut
sub span
{
my $this = shift;
return $this->{i}
}
=item C<< $span = $i->to_string >>
Returns an ISO 8601 formatted string representing the interval.
=cut
sub to_string
{
my $this = shift;
my $D = HTML::Microformats::Datatype::Duration->new($this->{i}->duration);
return $this->{i}->start . "/$D";
}
sub TO_JSON
{
my $this = shift;
return $this->to_string;
}
=item C<< $d->datatype >>
Returns an the RDF datatype URI representing the data type of this literal.
=back
=cut
sub datatype
{
my $self = shift;
return 'urn:iso:std:iso:8601#timeInterval';
}
=head2 Function
=over 4
=item C<< compare($a, $b) >>
Compares intervals $a and $b. Return values are as per 'cmp' (see L<perlfunc>).
This function is not exported by default.
Can also be used as a method:
$a->compare($b);
=back
=cut
sub compare
{
my $this = shift;
my $that = shift;
return ("$this" cmp "$that");
}
1;
__END__
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats>,
L<HTML::Microformats::Datatype>,
L<DateTime::Span>.
=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
|