File: RelEnclosure.pm

package info (click to toggle)
libhtml-microformats-perl 0.105-2%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 988 kB
  • ctags: 722
  • sloc: perl: 14,121; makefile: 24
file content (164 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download | duplicates (4)
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
=head1 NAME

HTML::Microformats::Format::RelEnclosure - the rel-enclosure microformat

=head1 SYNOPSIS

 my @enclosures = HTML::Microformats::Format::RelEnclosure->extract_all(
                   $doc->documentElement, $context);
 foreach my $e (@enclosures)
 {
   my $type = $l->get_type || 'unknown';
   printf("%s (%s)\n"), $l->get_href, $type);
 }

=head1 DESCRIPTION

HTML::Microformats::Format::RelEnclosure inherits from HTML::Microformats::Format_Rel. See the
base class definition for a description of property getter/setter methods,
constructors, etc.

=head2 Additional Method

=over 4

=item C<< $relenc->get_type() >>

Returns the media type (Content-Type) of the resource being linked to. This
is taken from the HTML 'type' attribute, so if that's not present, returns undef.

=back

=cut

package HTML::Microformats::Format::RelEnclosure;

use base qw(HTML::Microformats::Format_Rel);
use strict qw(subs vars); no warnings;
use 5.010;

use HTML::Microformats::Datatype::String qw(isms);

use Object::AUTHORITY;

BEGIN {
	$HTML::Microformats::Format::RelEnclosure::AUTHORITY = 'cpan:TOBYINK';
	$HTML::Microformats::Format::RelEnclosure::VERSION   = '0.105';
}

sub new
{
	my $class = shift;
	my $self  = $class->SUPER::new(@_);
	
	$self->{'DATA'}->{'type'} = $self->{'element'}->getAttribute('type')
		if $self->{'element'}->hasAttribute('type');

	return $self;
}

sub format_signature
{
	return {
		'rel'      => 'enclosure' ,
		'classes'  => [
				['type',     '?#'] ,
				['href',     '1#'] ,
				['label',    '1#'] ,
				['title',    '1#'] ,
			] ,
		'rdf:type' => [] ,
		'rdf:property' => {} ,
		}
}

sub profiles
{
	return qw(http://purl.org/uF/rel-enclosure/0.1/);
}

sub add_to_model
{
	my $self  = shift;
	my $model = shift;

	my $enc  = 'http://purl.oclc.org/net/rss_2.0/enc#';
	
	$model->add_statement(RDF::Trine::Statement->new(
		RDF::Trine::Node::Resource->new($self->context->document_uri),
		RDF::Trine::Node::Resource->new("${enc}enclosure"),
		RDF::Trine::Node::Resource->new($self->data->{'href'}),
		));
		
	$model->add_statement(RDF::Trine::Statement->new(
		RDF::Trine::Node::Resource->new($self->data->{'href'}),
		RDF::Trine::Node::Resource->new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
		RDF::Trine::Node::Resource->new("${enc}Enclosure"),
		));

	$model->add_statement(RDF::Trine::Statement->new(
		RDF::Trine::Node::Resource->new($self->data->{'href'}),
		RDF::Trine::Node::Resource->new("${enc}type"),
		RDF::Trine::Node::Literal->new(''.$self->data->{'type'}),
		))
		if defined $self->data->{'type'};

	$model->add_statement(RDF::Trine::Statement->new(
		RDF::Trine::Node::Resource->new($self->data->{'href'}),
		RDF::Trine::Node::Resource->new("http://www.w3.org/2000/01/rdf-schema#label"),
		$self->_make_literal($self->data->{'label'}),
		));

	$model->add_statement(RDF::Trine::Statement->new(
		RDF::Trine::Node::Resource->new($self->data->{'href'}),
		RDF::Trine::Node::Resource->new("http://purl.org/dc/terms/title"),
		$self->_make_literal($self->data->{'title'}),
		));

	return $self;
}

1;

=head1 MICROFORMAT

HTML::Microformats::Format::RelEnclosure supports rel-enclosure as described at
L<http://microformats.org/wiki/rel-enclosure>.

The "title" attribute on the link, and the linked text are taken to be significant.

=head1 RDF OUTPUT

Data is returned using the RSS Enclosures vocabulary
(L<http://purl.oclc.org/net/rss_2.0/enc#>) and occasional other terms.

=head1 BUGS

Please report any bugs to L<http://rt.cpan.org/>.

=head1 SEE ALSO

L<HTML::Microformats::Format_Rel>,
L<HTML::Microformats>,
L<HTML::Microformats::Format::hAtom>.

=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