File Coverage

blib/lib/Data/Seek/Search/Result.pm
Criterion Covered Total %
statement 47 47 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 61 61 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Data::Seek Search Result Class
2             package Data::Seek::Search::Result;
3              
4 3     3   730 use 5.10.0;
  3         10  
  3         120  
5 3     3   21 use strict;
  3         4  
  3         73  
6 3     3   14 use warnings;
  3         4  
  3         88  
7              
8 3     3   907 use Data::Seek::Data;
  3         5  
  3         70  
9 3     3   489 use Data::Seek::Exception;
  3         4  
  3         66  
10 3     3   660 use Data::Seek::Search;
  3         7  
  3         88  
11              
12 3     3   14 use Mo 'builder';
  3         4  
  3         15  
13              
14             our $VERSION = '0.05'; # VERSION
15              
16             has 'datasets',
17             builder => '_build_datasets';
18              
19             sub _build_datasets {
20 47     47   447 my $self = shift;
21 47         133 my $search = $self->search;
22 47         258 return $search->perform;
23             }
24              
25             has 'search',
26             default => sub { Data::Seek::Search->new };
27              
28             sub data {
29 1     1 1 691 my $self = shift;
30 1         6 my $sets = $self->datasets;
31 1         3 my $data = {};
32              
33 1         2 for my $set (@$sets) {
34 2         3 for my $node (@{$$set{nodes}}) {
  2         5  
35 4         11 $$data{$node} = $$set{dataset}{$node};
36             }
37             }
38              
39 1         12 $data = Data::Seek::Data->new(object => $data);
40 1         18 return $data->decode;
41             }
42              
43             sub nodes {
44 1     1 1 3864 my $self = shift;
45 1         16 my $sets = $self->datasets;
46 1         10 my $keys = [];
47              
48 1         3 for my $set (@$sets) {
49 2         4 push @$keys, sort @{$$set{nodes}};
  2         10  
50             }
51              
52 1         8 return $keys;
53             }
54              
55             sub values {
56 47     47 1 680 my $self = shift;
57 47         167 my $sets = $self->datasets;
58 36         90 my $vals = [];
59              
60 36         88 for my $set (@$sets) {
61 37         56 push @$vals, $$set{dataset}{$_} for sort @{$$set{nodes}};
  37         513  
62             }
63              
64 36         263 return $vals;
65             }
66              
67             1;
68              
69             __END__
70              
71             =pod
72              
73             =encoding UTF-8
74              
75             =head1 NAME
76              
77             Data::Seek::Search::Result - Data::Seek Search Result Class
78              
79             =head1 VERSION
80              
81             version 0.05
82              
83             =head1 SYNOPSIS
84              
85             use Data::Seek::Search::Result;
86              
87             =head1 DESCRIPTION
88              
89             Data::Seek::Search::Result is a class within L<Data::Seek> which provides access
90             to the search results produced by L<Data::Seek::Search>.
91              
92             =head1 ATTRIBUTES
93              
94             =head2 datasets
95              
96             my $dataset = $result->dataset;
97              
98             Perform the search and introspection using the search object,
99             L<Data::Seek::Search>, and cache the resulting data set.
100              
101             =head2 search
102              
103             my $search = $result->search;
104              
105             Reference the search object, L<Data::Seek::Search>, which the resulting data set
106             is derived from.
107              
108             =head1 METHODS
109              
110             =head2 data
111              
112             my $data = $result->data;
113              
114             Produce a data structure, i.e. a hash reference, comprised of only the nodes
115             matching the criteria used in the search.
116              
117             =head2 nodes
118              
119             my $nodes = $result->nodes;
120              
121             Produce a data structure, i.e. an array reference, comprised of only the node
122             keys/paths matching the criteria used in the search.
123              
124             =head2 values
125              
126             my $values = $result->values;
127              
128             Produce a data structure, i.e. an array reference, comprised of only the values
129             matching the criteria used in the search.
130              
131             =encoding utf8
132              
133             =head1 AUTHOR
134              
135             Al Newkirk <anewkirk@ana.io>
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is copyright (c) 2014 by Al Newkirk.
140              
141             This is free software; you can redistribute it and/or modify it under
142             the same terms as the Perl 5 programming language system itself.
143              
144             =cut