DAIA/Message.pm

filter: Statementstmt 82.3% 28 / 34 Branchbran 64.2% 9 / 14 Conditioncond 77.7% 7 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 77.0% 57 / 74 CC 11 SCAR 14.3
CC
11
Cov
77%
_buildargs
7.4
rdfhash
6.0
__ANON__
3.3
CRAP 4.2
« DAIA/Entity.pm ↑ Summary DAIA/Unavailable.pm »
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package DAIA::Message;
4 #ABSTRACT: An optional information or error message
5 11 our $VERSION = '0.43'; #VERSION
6  
7 11 ▶use base 'DAIA::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 our $DEFAULT_LANG = 'en';
10  
11 our %PROPERTIES = (
12 content => {
13 default => '',
14 64 ▶ filter => sub { "$_[0]" } # stringify everything
Subroutine __ANON__: called CC=1 SCAR=0.0
15 },
16 lang => {
17 43 ▶ default => sub { $DEFAULT_LANG },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 28 ▶ filter => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
19 28 ▶ is_language_tag("$_[0]") ? lc("$_[0]") : undef;
Branch: 1 branch
BranchTrueFalseTotal
is_language_tag("$_[0]") ? : 27 1 28
20 },
21 },
22 errno => {
23 default => undef,
24 2 ▶ filter => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
25 2 ▶ return unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 2 2
26 2 ▶ $_[0] =~ m/^-?\d+$/ ? $_[0] : 0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^-?\d+$/ ? : 2 0 2
27 },
28 }
29 11 );
30  
31 # called by the constructor
32 55 ▶sub _buildargs {
Subroutine _buildargs: called CC=7 SCAR=20.0
33 55 my $self = shift;
34 55 ▶ if ( @_ % 2 ) { # content as first parameter
Branch: 2 branches
BranchTrueFalseTotal
if (@_ % 2) { } 42 13 55
elsif (defined $_[0] and not defined $DAIA::Message::PROPERTIES{$_[0]} and is_language_tag($_[0])) { } 5 8 13
35 42 my ($content, %p) = @_;
36 42 ▶ if ( @_ == 3 and not defined $PROPERTIES{$_[1]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3 and not defined $DAIA::Message::PROPERTIES{$_[1]}) { } 0 42 42
Condition66%2/3
@_ == 3 and not defined $DAIA::Message::PROPERTIES{$_[1]}
!ll&&!rl&&r
4020
MC/DC0%0/2
@_ == 3 and not defined $DAIA::Message::PROPERTIES{$_[1]}
@_ == 3 not defined $DAIA::Message::PROPERTIES{$_[1]}
Truth table66%2/3
A and not(B)
A= @_ == 3B= not defined $DAIA::Message::PROPERTIES{$_[1]}
ABresult
0X0
100
111
37 0 return ( lang => $_[0], content => $_[1] );
38 } else {
39 42 return ( content => $content, %p );
40 }
41 ▶ } elsif ( defined $_[0] and not defined $PROPERTIES{$_[0]} and is_language_tag($_[0]) ) {
Condition83%5/6
defined $_[0] and not defined $DAIA::Message::PROPERTIES{$_[0]} and is_language_tag($_[0])
!ll&&!rl&&r
805
defined $_[0] and not defined $DAIA::Message::PROPERTIES{$_[0]}
!ll&&!rl&&r
175
MC/DC66%2/3
defined $_[0] and not defined $DAIA::Message::PROPERTIES{$_[0]} and is_language_tag($_[0])
defined $_[0] not defined $DAIA::Message::PROPERTIES{$_[0]} is_language_tag($_[0])
Truth table75%3/4
A and not(B) and C
A= defined $_[0]B= not defined $DAIA::Message::PROPERTIES{$_[0]}C= is_language_tag($_[0])
ABCresult
0XX0
10X0
1100
1111
42 5 my ($lang, $content, %p) = @_;
43 5 return ( lang => $lang, content => $content, %p );
44 } else {
45 8 return @_;
46 }
47  
48 0 return @_;
49 }
50  
51 0 ▶sub rdfhash {
Subroutine rdfhash: not called CC=2 SCAR=17.9
Pod documented
52 0 my $self = shift;
53 0 my $rdf = { type => 'literal', value => $self->{content} };
54 0 ▶ $rdf->{lang} = $self->{lang} if $self->{lang};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lang"} 0 0 0
55 0 return $rdf;
56 }
57  
58 33 ▶sub is_language_tag {
Subroutine is_language_tag: called CC=1 SCAR=0.0
Pod documented
59 33 my($tag) = lc($_[0]);
60 33 return $tag =~ /^[a-z]{1,8}(-[a-z0-9]{1,8})*$/;
61 }
62  
63 11 1;
64  
65 __END__
« DAIA/Entity.pm ↑ Summary DAIA/Unavailable.pm »