OPDS/OpenSearch/Query.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 90.0% 45 / 50 CC 5 SCAR 12.0
CC
5
Cov
88%
attributes_hashref
5.6
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« OPDS/Acquisition.pm ↑ Summary OPDS/Navigation.pm »
1 package XML::OPDS::OpenSearch::Query;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Types::Standard qw/Maybe Str Enum Int/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 XML::OPDS::OpenSearch::Query - OpenSearch query element for XML::OPDS
11  
12 =head1 DESCRIPTION
13  
14 This module is mostly an helper to provide validation to create
15 C<Query> elements in an OPDS search result. Notably, this doesn't
16 expand to XML.
17  
18 =head1 SYNOPSIS
19  
20 use XML::OPDS;
21 use XML::OPDS::OpenSearch::Query;
22 use Data::Page;
23 my $feed = XML::OPDS->new;
24 my $query = XML::OPDS::OpenSearch::Query->new(role => "example",
25 searchTerms => "my terms",
26 );
27 my $pager = Data::Page->new;
28 $pager->total_entries(50);
29 $pager->entries_per_page(20);
30 $pager->current_page(1);
31 $feed->search_result_pager($pager);
32 $feed->search_result_terms('my terms');
33  
34 # please note that if you set the search_result_pager and
35 # search_result_terms a role:request query is added automatically, so
36 # here we add only the example.
37  
38 $feed->search_result_queries([$query]);
39 print $feed->render;
40  
41 =head1 SETTERS/ACCESSORS
42  
43 All of them are optionals except C<role>.
44  
45 =head2 role
46  
47 Role values (from L<http://www.opensearch.org/Specifications/OpenSearch/1.1#Role_values>)
48  
49 =over 4
50  
51 =item request
52  
53 Represents the search query that can be performed to retrieve the same
54 set of search results.
55  
56 =item example
57  
58 Represents a search query that can be performed to demonstrate the search engine.
59  
60 =item related
61  
62 Represents a search query that can be performed to retrieve similar
63 but different search results.
64  
65 =item correction
66  
67 Represents a search query that can be performed to improve the result
68 set, such as with a spelling correction.
69  
70 =item subset
71  
72 Represents a search query that will narrow the current set of search results.
73  
74 =item superset
75  
76 Represents a search query that will broaden the current set of search results.
77  
78 =back
79  
80 =cut
81  
82 4 has role => (is => 'rw',
83 isa => Enum[qw/role request example related correction subset superset/]);
84  
85 =head2 title
86  
87 Contains a human-readable plain text string describing the search request.
88  
89 Restrictions: The value must contain 256 or fewer characters of plain
90 text. The value must not contain HTML or other markup.
91  
92 This object stores an arbitrary string, but cut it at 256 when
93 producing the attributes.
94  
95 =head2 totalResults
96  
97 Integer.
98  
99 Contains the expected number of results to be found if the search request were made.
100  
101 =head2 searchTerms
102  
103 String.
104  
105 Contains the value representing the "searchTerms" as an OpenSearch 1.1 parameter.
106  
107 The URI escaping is performed by the module.
108  
109 =head2 count
110  
111 Integer.
112  
113 Replaced with the number of search results per page desired by the search client.
114  
115 =head2 startIndex
116  
117 Integer.
118  
119 Replaced with the index of the first search result desired by the search client.
120  
121 =head2 startPage
122  
123 Integer.
124  
125 Replaced with the page number of the set of search results desired by the search client.
126  
127 =head2 language
128  
129 String. The value must conform to the XML 1.0 Language Identification,
130 as specified by RFC 5646. In addition, a value of "*" will signify
131 that the search client desires search results in any language.
132  
133 This module passes it verbatim.
134  
135 =head2 inputEncoding
136  
137 The value must conform to the XML 1.0 Character Encodings, as
138 specified by the IANA Character Set Assignments.
139  
140 This module passes it verbatim.
141  
142 =head2 outputEncoding
143  
144 Same as above.
145  
146 =head1 METHODS
147  
148 =head2 attributes_hashref
149  
150 Return the attributes which are defined in an hashref. The C<title> is
151 mangled to 256 characters and
152  
153 =head1 SEE ALSO
154  
155 Specification: L<http://www.opensearch.org/Specifications/OpenSearch/1.1>
156  
157 =cut
158  
159 4 has title => (is => 'rw', isa => Maybe[Str]);
160 4 has totalResults => (is => 'rw', isa => Maybe[Int]);
161 4 has searchTerms => (is => 'rw', isa => Maybe[Str]);
162 4 has count => (is => 'rw', isa => Maybe[Int]);
163 4 has startIndex => (is => 'rw', isa => Maybe[Int]);
164 4 has startPage => (is => 'rw', isa => Maybe[Int]);
165 4 has language => (is => 'rw', isa => Maybe[Str]);
166 4 has inputEncoding => (is => 'rw', isa => Maybe[Str]);
167 4 has outputEncoding => (is => 'rw', isa => Maybe[Str]);
168  
169 sub attributes_hashref {
170 8 ▶ my $self = shift;
Subroutine attributes_hashref: called CC=5 SCAR=17.3
Pod documented
171 8 my %out = (role => $self->role);
172 8 ▶ if (defined $self->title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->title) 0 8 8
173 0 $out{title} = substr $self->title, 0, 256;
174 }
175 8 ▶ if (defined $self->searchTerms) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->searchTerms) 8 0 8
176 8 $out{searchTerms} = URI::Escape::uri_escape($self->searchTerms);
177 }
178 8 foreach my $accessor (qw/totalResults
179 count
180 startIndex
181 startPage
182 language
183 inputEncoding
184 outputEncoding/) {
185 56 my $v = $self->$accessor;
186 56 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 56 56
187 0 $out{$accessor} = $v;
188 }
189 }
190 8 return \%out;
191 }
192  
193 4 1;
« OPDS/Acquisition.pm ↑ Summary OPDS/Navigation.pm »