OpenSearch/Response.pm

filter: Statementstmt 83.8% 78 / 93 Branchbran 33.3% 4 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.0% 22 / 25 Podpod 100% 14 / 14 totaltotal 80.9% 119 / 147 CC 11 SCAR 12.5
CC
11
Cov
78%
add_attribute
12.0
get_mtime
9.4
as_hash
3.0
CRAP 3.5
« OpenSearch/Response/ExtJS.pm ↑ Summary OpenSearch/Response/Tiny.pm »
1 package Search::OpenSearch::Response;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 use Types::Standard
4 2 ▶ qw( Int Str Num ArrayRef HashRef InstanceOf Maybe Object Bool );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Pageset;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 use overload
8 3 ▶ '""' => sub { $_[0]->stringify; },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
9 3 ▶ 'bool' => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
10 2 fallback => 1;
11  
12 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 has 'engine' => ( is => 'rw', isa => Maybe [Str] );
15 2 has 'results' => ( is => 'rw', isa => ArrayRef );
16 2 has 'total' => ( is => 'rw', isa => Int );
17 2 has 'offset' => ( is => 'rw', isa => Maybe [Int], builder => 'init_offset' );
18 2 has 'page_size' =>
19 ( is => 'rw', isa => Maybe [Int], builder => 'init_page_size' );
20 2 has 'fields' => ( is => 'rw', isa => Maybe [ArrayRef] );
21 2 has 'facets' => ( is => 'rw', isa => Maybe [HashRef] );
22 2 has 'query' => (
23 is => 'rw',
24 isa => Maybe [ Str | InstanceOf ['Search::Query::Dialect'] ]
25 );
26 2 has 'parsed_query' => (
27 is => 'rw',
28 isa => Maybe [ Str | InstanceOf ['Search::Query::Dialect'] ]
29 );
30 2 has 'json_query' => ( is => 'rw', isa => Str );
31 2 has 'title' => ( is => 'rw', isa => Maybe [Str], builder => 'init_title', );
32 2 has 'link' => ( is => 'rw', isa => Maybe [Str], builder => 'init_link' );
33 2 has 'author' => ( is => 'rw', isa => Maybe [Str], builder => 'init_author' );
34 2 has 'search_time' => ( is => 'rw', isa => Num );
35 2 has 'build_time' => ( is => 'rw', isa => Num );
36 2 has 'sort_info' => ( is => 'rw', isa => Str );
37 2 has 'version' => ( is => 'rw', isa => Str, builder => 'get_version' );
38 2 has 'suggestions' => ( is => 'rw', isa => ArrayRef );
39 has 'debug' =>
40 3 ▶ ( is => 'rw', isa => Bool, default => sub { $ENV{SOS_DEBUG} || 0 } );
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SOS_DEBUG"} or 0 0 3 3
41 3 ▶has 'pps' => ( is => 'rw', isa => Maybe [Int], default => sub {10} );
Subroutine __ANON__: called CC=1 SCAR=0.0
42 2 has 'error' => ( is => 'rw', isa => Maybe [Str] );
43 2 has 'attr_blacklist' =>
44 ( is => 'rw', isa => HashRef, builder => 'init_attr_blacklist' );
45 2 has 'mtime_field' =>
46 ( is => 'rw', isa => Str, builder => 'init_mtime_field' );
47  
48 2 our $VERSION = '0.409';
49  
50 3 ▶sub init_attr_blacklist {
Subroutine init_attr_blacklist: called CC=1 SCAR=0.0
Pod documented
51 return {
52 3 error => 1,
53 debug => 1,
54 attr_blacklist => 1,
55 pps => 1,
56 mtime_field => 1,
57 };
58 }
59  
60 3 ▶sub init_mtime_field { return 'mtime' }
Subroutine init_mtime_field: called CC=1 SCAR=0.0
Pod documented
61  
62 1 ▶sub default_fields {
Subroutine default_fields: called CC=1 SCAR=0.0
Pod documented
63 1 return [qw( uri title summary mtime score )];
64 }
65  
66 3 ▶sub get_version {
Subroutine get_version: called CC=2 SCAR=7.0
Pod documented
67 3 my $self = shift;
68 3 ▶ my $class = ref $self ? ref($self) : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 3 0 3
69 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70 3 return ${"${class}::VERSION"};
71 }
72  
73 3 ▶sub init_author {
Subroutine init_author: called CC=1 SCAR=0.0
Pod documented
74 3 my $self = shift;
75 3 return ref($self);
76 }
77  
78 3 ▶sub init_title {'OpenSearch Results'}
Subroutine init_title: called CC=1 SCAR=0.0
Pod documented
79 3 ▶sub init_link {''}
Subroutine init_link: called CC=1 SCAR=0.0
Pod documented
80 3 ▶sub init_offset {0}
Subroutine init_offset: called CC=1 SCAR=0.0
Pod documented
81 3 ▶sub init_page_size {10}
Subroutine init_page_size: called CC=1 SCAR=0.0
Pod documented
82  
83 0 ▶sub stringify { croak "$_[0] does not implement stringify()" }
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
84  
85 3 ▶sub as_hash {
Subroutine as_hash: called CC=3 SCAR=11.0
Pod documented
86 3 my $self = shift;
87 3 my %hash;
88 3 my %class_attrs = map { $_->name => $_ } $self->meta->get_all_attributes;
89 3 for my $attr ( keys %class_attrs ) {
90 71 ▶ next if exists $self->attr_blacklist->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->attr_blacklist->{$attr} 15 56 71
91 56 $hash{$attr} = $self->$attr;
92 }
93 3 $hash{updated} = $self->get_mtime();
94 3 return \%hash;
95 }
96  
97 3 ▶sub get_mtime {
Subroutine get_mtime: called CC=5 SCAR=22.5
Pod documented
98 3 my $self = shift;
99 3 my $field = $self->mtime_field;
100 3 my $recent = 0;
101 3 ▶ for my $r ( @{ $self->results || [] } ) {
Condition50%1/2
$self->results || []
l!l
03
MC/DC0%0/1
$self->results || []
$self->results
Truth table50%1/2
A
A= $self->results
Aresult
11
00
102 0 ▶ next unless ref $r eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 0 0
103 0 my $mtime = $r->{$field};
104 0 ▶ if ( $mtime > $recent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime > $recent) 0 0 0
105 0 $recent = $mtime;
106 }
107 }
108 3 return $recent;
109 }
110  
111 0 ▶sub build_pager {
Subroutine build_pager: not called CC=1 SCAR=6.9
Pod documented
112 0 my $self = shift;
113 0 my $offset = $self->offset;
114 0 my $page_size = $self->page_size;
115 0 my $this_page = ( $offset / $page_size ) + 1;
116 0 my $pager = Data::Pageset->new(
117 { total_entries => $self->total,
118 entries_per_page => $page_size,
119 current_page => $this_page,
120 pages_per_set => $self->pps,
121 mode => 'slide',
122 }
123 );
124 0 return $pager;
125 }
126  
127 0 ▶sub add_attribute {
Subroutine add_attribute: not called CC=3 SCAR=24.8
Pod documented
128 0 my $self = shift;
129 0 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
130 0 for my $attr (@_) {
131 0 has $attr => ( is => 'rw', );
132 }
133 }
134  
135 2 1;
136  
137 __END__
« OpenSearch/Response/ExtJS.pm ↑ Summary OpenSearch/Response/Tiny.pm »