Mojito/Model/Doc/Mongo.pm

filter: Statementstmt 27.7% 15 / 54 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 80.0% 4 / 5 totaltotal 31.0% 23 / 74 CC 5 SCAR 20.6
CC
5
Cov
25%
get_docs_for_month
20.0
get_collection_pages
6.0
get_most_recent_docs
2.0
CRAP 7.8
« Mojito/Collection/CRUD/Deep.pm ↑ Summary Mojito/Role/DB/OID.pm »
1 4 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Model::Doc::Mongo;
3 4 $Mojito::Model::Doc::Mongo::VERSION = '0.25';
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use MongoDB::OID;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 with('Mojito::Role::DB::Mongo');
9  
10 =head1 Methods
11  
12 =head2 get_most_recent_docs
13  
14 Get the documents sorted by date in reverse chrono order.
15 Returns a cursor to them.
16  
17 =cut
18  
19 0 ▶sub get_most_recent_docs {
Subroutine get_most_recent_docs: not called CC=1 SCAR=6.9
Pod documented
20 0 my $self = shift;
21 0 return $self->collection->find->sort( { last_modified => -1 } );
22 }
23  
24 =head2 get_feed_docs
25  
26 Get the documents for a particular feed sorted by date in reverse chrono order.
27 Returns a cursor to them.
28  
29 =cut
30  
31 0 ▶sub get_feed_docs {
Subroutine get_feed_docs: not called CC=1 SCAR=6.9
Pod documented
32 0 my ($self, $feed) = @_;
33 0 return $self->collection->find({feeds => $feed})->sort( { last_modified => -1 } );
34 }
35  
36 =head2 get_collections
37  
38 Get the collections by name sorted by date in reverse chrono order.
39 Returns a cursor to them.
40  
41 =cut
42  
43 0 ▶sub get_collections {
Subroutine get_collections: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self = shift;
45 0 $self->clear_collection_name;
46 0 $self->clear_collection;
47 0 $self->collection_name('collection');
48 0 return $self->collection->find->sort( { last_modified => -1 } );
49 }
50  
51 =head2 get_collection_pages
52  
53 Get the pages belonging to a particular collection.
54 NOTE: We get the list of page ids from the collection collected_page_ids value.
55 Then we find all documents corresponding to those ids.
56  
57 Return an (collection_name, ArrayRef of pages);
58 =cut
59  
60 0 ▶sub get_collection_pages {
Subroutine get_collection_pages: not called CC=2 SCAR=17.9
Pod documented
61 0 my ($self, $collection_id) = (shift, shift);
62  
63  
64 0 $self->clear_collection_name;
65 0 $self->clear_collection;
66 0 $self->collection_name('collection');
67 0 my $oid = MongoDB::OID->new( value => $collection_id );
68 0 my $collection = $self->collection->find_one( { _id => $oid } );
69 0 my $page_ids = $collection->{collected_page_ids};
70 0 my @page_oids = map { MongoDB::OID->new( value => $_ ) } @{$page_ids};
71
72 # Change to notes collection
73 0 $self->clear_collection_name;
74 0 $self->clear_collection;
75 0 $self->collection_name('notes');
76 0 my @pages;
77 0 foreach my $oid (@page_oids) {
78 0 my $page = $self->collection->find_one( { _id => $oid } );
79 0 push @pages, $page;
80 }
81 0 return ($collection->{collection_name}, \@pages);
82 }
83  
84 0 ▶sub get_docs_for_month {
Subroutine get_docs_for_month: not called CC=4 SCAR=30.0
Pod undocumented
85 0 my ($self, $month, $year) = @_;
86  
87 0 my %monthly_data = ();
88 0 my $start_epoch = DateTime->new(
89 year => $year,
90 month => $month,
91 day => 1,
92 hour => 0,
93 minute => 0,
94 second => 0,
95 )->epoch;
96 0 ▶ my $next_month = ($month == 12) ? 1 : $month + 1;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
97 0 ▶ my $year_of_next_month = ($month == 12) ? $year + 1 : $year;
Branch: 1 branch
BranchTrueFalseTotal
$month == 12 ? : 0 0 0
98 0 my $end_epoch = DateTime->new(
99 year => $year_of_next_month,
100 month => $next_month,
101 day => 1,
102 hour => 0,
103 minute => 0,
104 second => 0,
105 )->epoch;
106 0 my $docs = $self->collection->find(
107 { 'last_modified' => { '$gte' => $start_epoch, '$lt' => $end_epoch } });
108 0 ▶ while (my $doc = $docs->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $docs->next) 0 0 0
109 0 my $day = DateTime->from_epoch(epoch => $doc->{last_modified})->day;
110 0 push @{ $monthly_data{$day} },
111 0 { id => $doc->{_id}->value, title => $doc->{title} };
112 }
113 0 return %monthly_data;
114 }
115  
116 4 1
117  
118 __END__
« Mojito/Collection/CRUD/Deep.pm ↑ Summary Mojito/Role/DB/OID.pm »