| 1 | package Dallycot::Value::String; | ||||||||||||||||||||||||||||||||||
| 2 | 30 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: A string with an associated language | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 30 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 30 | ▶ | use parent 'Dallycot::Value::Any'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 30 | ▶ | use experimental qw(switch); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 30 | ▶ | use Promises qw(deferred); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | sub new { | ||||||||||||||||||||||||||||||||||
| 17 | 1064 | ▶ | my ( $class, $value, $lang ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 1064 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 1064 | ▶ | return bless [ $value // '', $lang // 'en' ] => $class; | ||||||||||||||||||||||||||||||||
|
Condition75%3/4
$value // ""
$lang // "en"
MC/DC0%0/1
$value // ""
$value
MC/DC100%1/1
$lang // "en"
$lang
Truth table50%1/2
A
A= $value
Truth table100%2/2
A
A= $lang
| |||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | sub to_rdf { | ||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ( $self, $model ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
to_rdf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 0 | return $model -> string( $self -> value, $self -> lang ); | |||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | sub lang { return shift->[1] } | ||||||||||||||||||||||||||||||||
|
Subroutine
lang: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | sub id { | ||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | 0 | return $self->[0] . "@" . $self->[1] . "^^String"; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | sub fetch_property { | ||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my ( $self, $engine, $prop ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
fetch_property: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
as_text: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( $self->[1] eq 'en' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | 0 | return qq{"$val"}; | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||||||||
| 66 | 0 | return qq{"$val"\@} . $self->[1]; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | sub is_defined { | ||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_defined: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 0 | return length( $self->value ) != 0; | |||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | sub prepend { | ||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | my ( $self, @things ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
prepend: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 3 | return __PACKAGE__->new( join( "", ( map { $_->value } reverse @things ), $self->value ) ); | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | sub calculate_length { | ||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
calculate_length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 1 | return Dallycot::Value::Numeric->new( length $self->[0] ); | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | sub calculate_reverse { | ||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
calculate_reverse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 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 | 2 | ▶ | my ( $self, $engine, $offset, $length ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
take_range: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 2 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if ( abs($offset) > length( $self->[0] ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | 0 | $d->resolve( $self->new( '', $self->lang ) ); | |||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||
| 107 | 2 | $d->resolve( $self->new( substr( $self->value, $offset - 1, $length - $offset + 1 ), $self->lang ) ); | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 2 | return $d->promise; | |||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | sub drop { | ||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | my ( $self, $engine, $offset ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 1 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | if ( abs($offset) > length( $self->value ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | 0 | $d->resolve( $self->new( '', $self->lang ) ); | |||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||
| 122 | 1 | $d->resolve( $self->new( substr( $self->value, $offset ), $self->lang ) ); | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 1 | return $d->promise; | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | sub value_at { | ||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | my ( $self, $engine, $index ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
value_at: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 1 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | if ( !$index || abs($index) > length( $self->[0] ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $index or abs $index > length $self->[0]
MC/DC0%0/2
not $index or abs $index > length $self->[0]
not $index
abs $index > length $self->[0]
Truth table33%1/3
not(A) or B
A= not $indexB= abs $index > length $self->[0]
| |||||||||||||||||||||||||||||||||||
| 134 | 0 | $d->resolve( $self->new( '', $self->[1] ) ); | |||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||
| 137 | 1 | $d->resolve( $self->new( substr( $self->[0], $index - 1, 1 ), $self->[1] ) ); | |||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 1 | return $d->promise; | |||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | sub resolve { | ||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
resolve: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $self, $engine, $other ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_equal: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 0 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $d->resolve( $self->lang eq $other->lang && $self->value eq $other->value ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->lang eq $other->lang && $self->value eq $other->value
MC/DC0%0/2
$self->lang eq $other->lang && $self->value eq $other->value
$self->lang eq $other->lang
$self->value eq $other->value
Truth table0%0/3
A && B
A= $self->lang eq $other->langB= $self->value eq $other->value
| |||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | 0 | return $d->promise; | |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | sub is_less { | ||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my ( $self, $engine, $other ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_less: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 0 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $d->resolve( $self->lang lt $other->lang | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->lang lt $other->lang || $self->lang eq $other->lang && $self->value lt $other->value
$self->lang eq $other->lang and $self->value lt $other->value
MC/DC0%0/3
$self->lang lt $other->lang || $self->lang eq $other->lang && $self->value lt $other->value
$self->lang lt $other->lang
$self->lang eq $other->lang
$self->value lt $other->value
Truth table0%0/4
A || B and C
A= $self->lang lt $other->langB= $self->lang eq $other->langC= $self->value lt $other->value
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $self, $engine, $other ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_less_or_equal: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | 0 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $d->resolve( $self->lang lt $other->lang | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->lang lt $other->lang || $self->lang eq $other->lang && $self->value le $other->value
$self->lang eq $other->lang and $self->value le $other->value
MC/DC0%0/3
$self->lang lt $other->lang || $self->lang eq $other->lang && $self->value le $other->value
$self->lang lt $other->lang
$self->lang eq $other->lang
$self->value le $other->value
Truth table0%0/4
A || B and C
A= $self->lang lt $other->langB= $self->lang eq $other->langC= $self->value le $other->value
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $self, $engine, $other ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_greater: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 0 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $d->resolve( $self->lang gt $other->lang | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->lang gt $other->lang || $self->lang eq $other->lang && $self->value gt $other->value
$self->lang eq $other->lang and $self->value gt $other->value
MC/DC0%0/3
$self->lang gt $other->lang || $self->lang eq $other->lang && $self->value gt $other->value
$self->lang gt $other->lang
$self->lang eq $other->lang
$self->value gt $other->value
Truth table0%0/4
A || B and C
A= $self->lang gt $other->langB= $self->lang eq $other->langC= $self->value gt $other->value
| |||||||||||||||||||||||||||||||||||
| 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 | ▶ | my ( $self, $engine, $other ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
is_greater_or_equal: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | 0 | my $d = deferred; | |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $d->resolve( $self->lang gt $other->lang | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->lang gt $other->lang || $self->lang eq $other->lang && $self->value ge $other->value
$self->lang eq $other->lang and $self->value ge $other->value
MC/DC0%0/3
$self->lang gt $other->lang || $self->lang eq $other->lang && $self->value ge $other->value
$self->lang gt $other->lang
$self->lang eq $other->lang
$self->value ge $other->value
Truth table0%0/4
A || B and C
A= $self->lang gt $other->langB= $self->lang eq $other->langC= $self->value ge $other->value
| |||||||||||||||||||||||||||||||||||
| 202 | || $self->lang eq $other->lang && $self->value ge $other->value ); | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | 0 | return $d->promise; | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 30 | 1; | |||||||||||||||||||||||||||||||||