Mojito/Model/Doc/Deep.pm

filter: Statementstmt 16.4% 12 / 73 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 3 / 8 Podpod 80.0% 4 / 5 totaltotal 17.9% 19 / 106 CC 12 SCAR 26.7
CC
12
Cov
13%
get_docs_for_month
30.0
get_most_recent_docs
12.0
get_feed_docs
12.0
CRAP 14.4
« Mojito.pm ↑ Summary Mojito/Model/Transform.pm »
1 4 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Model::Doc::Deep;
3 4 $Mojito::Model::Doc::Deep::VERSION = '0.25';
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 with('Mojito::Role::DB::Deep');
8  
9 =head1 Methods
10  
11 =head2 get_most_recent_docs
12  
13 {
14 id1 => {},
15 id2 => {}
16 }
17  
18 =cut
19  
20 0 ▶sub get_most_recent_docs {
Subroutine get_most_recent_docs: not called CC=3 SCAR=24.8
Pod documented
21 0 my ($self) = @_;
22 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
23 0 my $docs = $self->collection->export;
24 0 my @sorted_docs;
25 0 foreach my $id (
26 sort {
27 $docs->{$a}->{last_modified} <=> $docs->{$b}->{last_modified}
28 0 } keys %{$docs}
29 ) {
30 0 push @sorted_docs, $docs->{$id};
31 }
32 0 return [@sorted_docs];
33 }
34  
35 =head2 get_feed_docs
36  
37 Get the documents for a particular feed sorted by date in reverse chrono order.
38 Returns a cursor to them.
39  
40 =cut
41  
42 0 ▶sub get_feed_docs {
Subroutine get_feed_docs: not called CC=3 SCAR=24.8
Pod documented
43 0 my ($self, $feed) = @_;
44 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
45 0 my $collection = $self->collection->export;
46 0 my @docs = values %{$collection};
47 0 ▶ my @feed_docs = grep { $_->{feeds} && $_->{feeds} eq $feed } @docs;
Condition0%0/3
$_->{'feeds'} && $_->{'feeds'} eq $feed
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'feeds'} && $_->{'feeds'} eq $feed
$_->{'feeds'} $_->{'feeds'} eq $feed
Truth table0%0/3
A && B
A= $_->{'feeds'}B= $_->{'feeds'} eq $feed
ABresult
0X0
100
111
48 0 @feed_docs = sort { $a->{last_modified} <=> $b->{last_modified} } @feed_docs;
49 0 return \@feed_docs;
50 }
51  
52 =head2 get_collections
53  
54 Get the collections by name sorted by date in reverse chrono order.
55 Returns a cursor to them.
56  
57 =cut
58  
59 0 ▶sub get_collections {
Subroutine get_collections: not called CC=3 SCAR=24.8
Pod documented
60 0 my $self = shift;
61
62 0 $self->clear_collection_name;
63 0 $self->clear_collection;
64 0 $self->collection_name('collection');
65 0 ▶ return [] if !$self->collection;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collection 0 0 0
66 0 my $collections = $self->collection->export;
67 0 my @sorted_collections;
68 0 foreach my $id (
69 sort {
70 $collections->{$a}->{last_modified} <=> $collections->{$b}->{last_modified}
71 0 } keys %{$collections}
72 ) {
73 0 push @sorted_collections, $collections->{$id};
74 }
75 0 return [@sorted_collections];
76 }
77  
78 =head2 get_collection_pages
79  
80 Get the pages belonging to a particular collection.
81 NOTE: We get the list of page ids from the collection collected_page_ids value.
82 Then we find all documents corresponding to those ids.
83  
84 Return an (collection_name, ArrayRef of pages);
85 =cut
86  
87 0 ▶sub get_collection_pages {
Subroutine get_collection_pages: not called CC=2 SCAR=17.9
Pod documented
88 0 my ($self, $collection_id) = @_;
89  
90 0 $self->clear_collection_name;
91 0 $self->clear_collection;
92 0 $self->collection_name('collection');
93 0 my $collection = $self->collection->{$collection_id}->export;
94 0 my $page_ids = $collection->{collected_page_ids};
95 # Change to notes collection
96 0 $self->clear_collection_name;
97 0 $self->clear_collection;
98 0 $self->collection_name('notes');
99 0 my @pages;
100 0 foreach my $id (@{$page_ids}) {
101 0 my $page = $self->collection->{$id};
102 0 push @pages, $page;
103 }
104 0 return ($collection->{collection_name}, \@pages);
105 }
106  
107 0 ▶sub get_docs_for_month {
Subroutine get_docs_for_month: not called CC=5 SCAR=34.0
Pod undocumented
108 0 my ($self, $month, $year) = @_;
109  
110 0 my %monthly_data = ();
111 0 my $start_epoch = DateTime->new(
112 year => $year,
113 month => $month,
114 day => 1,
115 hour => 0,
116 minute => 0,
117 second => 0,
118 )->epoch;
119 0 ▶ my $next_month = ($month == 12) ? 1 : $month + 1;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
120 0 ▶ my $year_of_next_month = ($month == 12) ? $year + 1 : $year;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
121 0 my $end_epoch = DateTime->new(
122 year => $year_of_next_month,
123 month => $next_month,
124 day => 1,
125 hour => 0,
126 minute => 0,
127 second => 0,
128 )->epoch;
129 0 my $docs = $self->collection->export;
130 0 ▶ my @docs = grep { ($_->{last_modified} >= $start_epoch) && ($_->{last_modified} <= $end_epoch) } values %{$docs};
Condition0%0/3
$_->{'last_modified'} >= $start_epoch && $_->{'last_modified'} <= $end_epoch
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'last_modified'} >= $start_epoch && $_->{'last_modified'} <= $end_epoch
$_->{'last_modified'} >= $start_epoch $_->{'last_modified'} <= $end_epoch
Truth table0%0/3
A && B
A= $_->{'last_modified'} >= $start_epochB= $_->{'last_modified'} <= $end_epoch
ABresult
0X0
100
111
131 0 foreach my $doc (@docs) {
132 0 my $day = DateTime->from_epoch(epoch => $doc->{last_modified})->day;
133 0 push @{ $monthly_data{$day} },
134 0 { id => $doc->{id}, title => $doc->{title} };
135 }
136 0 return %monthly_data;
137 }
138  
139 4 1;
« Mojito.pm ↑ Summary Mojito/Model/Transform.pm »