line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RDF::Lazy::Literal; |
2
|
9
|
|
|
9
|
|
107
|
use v5.10; |
|
9
|
|
|
|
|
29
|
|
3
|
9
|
|
|
9
|
|
43
|
use strict; |
|
9
|
|
|
|
|
57
|
|
|
9
|
|
|
|
|
182
|
|
4
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
236
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
44
|
use base 'RDF::Lazy::Node'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
935
|
|
7
|
9
|
|
|
9
|
|
51
|
use Scalar::Util qw(blessed); |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
605
|
|
8
|
9
|
|
|
9
|
|
48
|
use CGI qw(escapeHTML); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
58
|
|
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
993
|
use overload '""' => sub { shift->str; }; |
|
9
|
|
|
10
|
|
19
|
|
|
9
|
|
|
|
|
112
|
|
|
10
|
|
|
|
|
275576
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# not very strict check for language tag look-alikes (see www.langtag.net) |
13
|
|
|
|
|
|
|
our $LANGTAG = qr/^(([a-z]{2,8}|[a-z]{2,3}-[a-z]{3})(-[a-z0-9_]+)?-?)$/i; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
29
|
|
|
29
|
0
|
53
|
my $class = shift; |
17
|
29
|
|
33
|
|
|
107
|
my $graph = shift || RDF::Lazy->new; |
18
|
29
|
|
100
|
|
|
177
|
my $literal = shift // ''; |
19
|
|
|
|
|
|
|
|
20
|
29
|
|
|
|
|
724
|
my ($language, $datatype) = @_; |
21
|
|
|
|
|
|
|
|
22
|
29
|
100
|
|
|
|
117
|
if (defined $language) { |
23
|
8
|
100
|
|
|
|
73
|
if ($language =~ $LANGTAG) { |
|
|
50
|
|
|
|
|
|
24
|
5
|
|
|
|
|
12
|
$datatype = undef; |
25
|
|
|
|
|
|
|
} elsif( not defined $datatype ) { |
26
|
3
|
|
|
|
|
15
|
$datatype = $graph->uri($language)->trine; |
27
|
3
|
|
|
|
|
20
|
$language = undef; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
29
|
100
|
66
|
|
|
273
|
$literal = RDF::Trine::Node::Literal->new( $literal, $language, $datatype ) |
32
|
|
|
|
|
|
|
unless blessed($literal) and $literal->isa('RDF::Trine::Node::Literal'); |
33
|
29
|
50
|
|
|
|
599
|
return unless defined $literal; |
34
|
|
|
|
|
|
|
|
35
|
29
|
|
|
|
|
159
|
return bless [ $literal, $graph ], $class; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub str { |
39
|
|
|
|
|
|
|
shift->trine->literal_value |
40
|
20
|
|
|
20
|
1
|
673
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub lang { |
43
|
30
|
|
|
30
|
1
|
7660
|
my $self = shift; |
44
|
30
|
|
|
|
|
88
|
my $lang = $self->trine->literal_value_language; |
45
|
30
|
100
|
66
|
|
|
258
|
return $lang if not @_ or not $lang; |
46
|
|
|
|
|
|
|
|
47
|
17
|
|
50
|
|
|
74
|
my $xxx = lc(shift || ""); |
48
|
17
|
|
|
|
|
49
|
$xxx =~ s/_/-/g; |
49
|
17
|
50
|
|
|
|
111
|
return unless $xxx =~ $LANGTAG; |
50
|
|
|
|
|
|
|
|
51
|
17
|
100
|
100
|
|
|
113
|
if ( $xxx eq "$lang" or $xxx =~ s/-$// and index($lang, $xxx) == 0 ) { |
|
|
|
66
|
|
|
|
|
52
|
8
|
|
|
|
|
58
|
return $lang; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
9
|
|
|
|
|
55
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub datatype { |
59
|
12
|
|
|
12
|
1
|
5412
|
my $self = shift; |
60
|
12
|
|
|
|
|
49
|
my $type = $self->graph->resource( $self->trine->literal_datatype ); |
61
|
12
|
100
|
66
|
|
|
90
|
return $type unless @_ and $type; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
13
|
foreach (@_) { |
64
|
3
|
|
|
|
|
22
|
my $t = $self->graph->uri( $_ ); |
65
|
3
|
100
|
66
|
|
|
24
|
return 1 if $t->is_resource and $t->str eq $type->str; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _autoload { |
72
|
11
|
|
|
11
|
|
17
|
my $self = shift; |
73
|
11
|
|
|
|
|
17
|
my $method = shift; |
74
|
|
|
|
|
|
|
|
75
|
11
|
50
|
|
|
|
53
|
return unless $method =~ /^is_(.+)$/; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# We assume that no language is named 'blank', 'literal', or 'resource' |
78
|
11
|
100
|
|
|
|
28
|
return 1 if $self->lang($1); |
79
|
|
|
|
|
|
|
|
80
|
6
|
|
|
|
|
24
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
RDF::Lazy::Literal - Literal node in a RDF::Lazy graph |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
You should not directly create instances of this class. |
93
|
|
|
|
|
|
|
See L<RDF::Lazy::Node> for general node properties. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 str |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Return the literal string value of this node. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 esc |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Return the HTML-encoded literal string value. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 lang ( [ $pattern ] ) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Return the language tag (a BCP 47 language tag locator), if this node has one, |
108
|
|
|
|
|
|
|
or test whether the language tag matches a pattern. For instance use 'de' for |
109
|
|
|
|
|
|
|
plain German (but not 'de-AT') or 'de-' for plain German or any German dialect. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 is_... |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Return whether this node matches a given language tag, for instance |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$node->is_en # equivalent to $node->lang('en') |
116
|
|
|
|
|
|
|
$node->is_en_ # equivalent to $node->lang('en-') |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 datatype ( [ @types ] ) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Return the datatype (as L<RDF::Lazy::Resource>, if this node has one. |
121
|
|
|
|
|
|
|
Can also be used to checks whether the datatype matches, for instance: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$node->datatype('xsd:integer','xsd:double'); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |