File: Microdata0.pm

package info (click to toggle)
libhtml-html5-microdata-parser-perl 0.100-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 400 kB
  • sloc: perl: 4,036; makefile: 7; sh: 1
file content (53 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (3)
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
package HTML::HTML5::Microdata::Strategy::Microdata0;

use 5.010;
use strict;
use utf8;

our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION   = '0.100';

use URI::Escape qw[uri_escape];

use base qw[HTML::HTML5::Microdata::Strategy::Basic];

sub make_uri
{
	my ($self=>%params) = @_;
	
	if ($self->is_uri($params{name}))
	{
		return $params{name};
	}
	elsif (not length ($params{type}//''))
	{
		return undef unless $params{prefix_empty};
		return $params{prefix_empty}.uri_escape($params{name});
	}
	
	# Let predicate have the same value as [item type].
	my $predicate = $params{type};
	
	# If predicate does not contain a U+0023 NUMBER SIGN character (#),
	# then append a U+0023 NUMBER SIGN character (#) to predicate.
	$predicate .= '#' unless $predicate =~ /#/;
	
	# Append a U+003A COLON character (:) to predicate.
	$predicate .= ':';
	
	# Append the value of name to predicate, with any characters in name
	# that are not valid in the <ifragment> production of the IRI syntax
	# being %-escaped.
	# Generate the following triple:
	# predicate : the concatenation of the string
	# "http://www.w3.org/1999/xhtml/microdata#" and predicate, with any
	# characters in predicate that are not valid in the <ifragment>
	# production of the IRI syntax being %-escaped [RFC3987] 
	# TOBY-QUERY: should $name really get escaped twice??
	$predicate = 'http://www.w3.org/1999/xhtml/microdata#'
		. uri_escape($predicate . uri_escape($params{name}));

	return $predicate;
}

1;