line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::Value::String; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: A string with an associated language |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
1362
|
use strict; |
|
23
|
|
|
|
|
45
|
|
|
23
|
|
|
|
|
877
|
|
7
|
23
|
|
|
23
|
|
101
|
use warnings; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
700
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
87
|
use utf8; |
|
23
|
|
|
|
|
30
|
|
|
23
|
|
|
|
|
304
|
|
10
|
23
|
|
|
23
|
|
8018
|
use parent 'Dallycot::Value::Any'; |
|
23
|
|
|
|
|
4604
|
|
|
23
|
|
|
|
|
106
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1071
|
use experimental qw(switch); |
|
23
|
|
|
|
|
35
|
|
|
23
|
|
|
|
|
118
|
|
13
|
|
|
|
|
|
|
|
14
|
23
|
|
|
23
|
|
2711
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
100
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
4
|
|
|
4
|
0
|
21
|
my ( $class, $value, $lang ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
33
|
|
|
19
|
$class = ref $class || $class; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
50
|
|
|
38
|
return bless [ $value // '', $lang // 'en' ] => $class; |
|
|
|
50
|
|
|
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub to_rdf { |
25
|
0
|
|
|
0
|
0
|
|
my ( $self, $model ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $model -> string( $self -> value, $self -> lang ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
|
sub lang { return shift->[1] } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub id { |
33
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self->[0] . "@" . $self->[1] . "^^String"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub fetch_property { |
39
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $prop ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $d = deferred; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
given ($prop) { |
44
|
0
|
|
|
|
|
|
when ('@lang') { |
45
|
0
|
|
|
|
|
|
$d->resolve( Dallycot::Value::String->new( $self->lang, '' ) ); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
default { |
48
|
0
|
|
|
|
|
|
$d->resolve( Dallycot::Value::Undefined->new ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $d->promise; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub as_text { |
56
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $val = $self->value; |
59
|
0
|
|
|
|
|
|
$val =~ s{\\}{\\\\}g; |
60
|
0
|
|
|
|
|
|
$val =~ s{\n}{\\n}g; |
61
|
0
|
|
|
|
|
|
$val =~ s{"}{\\"}g; |
62
|
0
|
0
|
|
|
|
|
if ( $self->[1] eq 'en' ) { |
63
|
0
|
|
|
|
|
|
return qq{"$val"}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
|
return qq{"$val"\@} . $self->[1]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub is_defined { |
71
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return length( $self->value ) != 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub prepend { |
77
|
0
|
|
|
0
|
0
|
|
my ( $self, @things ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return __PACKAGE__->new( join( "", ( map { $_->value } reverse @things ), $self->value ) ); |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub calculate_length { |
83
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return Dallycot::Value::Numeric->new( length $self->[0] ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub calculate_reverse { |
89
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $d = deferred; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$d->resolve( $self->new( reverse( $self->value ), $self->lang ) ); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $d->promise; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub take_range { |
99
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $offset, $length ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $d = deferred; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ( abs($offset) > length( $self->[0] ) ) { |
104
|
0
|
|
|
|
|
|
$d->resolve( $self->new( '', $self->lang ) ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
|
$d->resolve( $self->new( substr( $self->value, $offset - 1, $length - $offset + 1 ), $self->lang ) ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $d->promise; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub drop { |
114
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $offset ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $d = deferred; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( abs($offset) > length( $self->value ) ) { |
119
|
0
|
|
|
|
|
|
$d->resolve( $self->new( '', $self->lang ) ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
|
$d->resolve( $self->new( substr( $self->value, $offset ), $self->lang ) ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $d->promise; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub value_at { |
129
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $index ) = @_; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $d = deferred; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
0
|
|
|
|
if ( !$index || abs($index) > length( $self->[0] ) ) { |
134
|
0
|
|
|
|
|
|
$d->resolve( $self->new( '', $self->[1] ) ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
0
|
|
|
|
|
|
$d->resolve( $self->new( substr( $self->[0], $index - 1, 1 ), $self->[1] ) ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $d->promise; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub resolve { |
144
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $d = deferred; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$d -> resolve($self); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return $d->promise; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub is_equal { |
154
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $other ) = @_; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $d = deferred; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
0
|
|
|
|
$d->resolve( $self->lang eq $other->lang && $self->value eq $other->value ); |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $d->promise; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub is_less { |
164
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $other ) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $d = deferred; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
0
|
|
|
|
$d->resolve( $self->lang lt $other->lang |
169
|
|
|
|
|
|
|
|| $self->lang eq $other->lang && $self->value lt $other->value ); |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $d->promise; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub is_less_or_equal { |
175
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $other ) = @_; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $d = deferred; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
0
|
|
|
|
$d->resolve( $self->lang lt $other->lang |
180
|
|
|
|
|
|
|
|| $self->lang eq $other->lang && $self->value le $other->value ); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $d->promise; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub is_greater { |
186
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $other ) = @_; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $d = deferred; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
0
|
|
|
|
$d->resolve( $self->lang gt $other->lang |
191
|
|
|
|
|
|
|
|| $self->lang eq $other->lang && $self->value gt $other->value ); |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return $d->promise; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub is_greater_or_equal { |
197
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $other ) = @_; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $d = deferred; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
0
|
|
|
|
$d->resolve( $self->lang gt $other->lang |
202
|
|
|
|
|
|
|
|| $self->lang eq $other->lang && $self->value ge $other->value ); |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return $d->promise; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |