Mojito/Page/CRUD/Mongo.pm

filter: Statementstmt 50.0% 18 / 36 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 5 / 10 Podpod 100% 5 / 5 totaltotal 45.9% 28 / 61 CC 3 SCAR 14.1
CC
3
Cov
43%
create
12.0
read
2.0
update
2.0
CRAP 4.1
« Mojito/Filter/Shortcuts.pm ↑ Summary Mojito/Role/DB/Elasticsearch.pm »
1 3 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Page::CRUD::Mongo;
3 3 $Mojito::Page::CRUD::Mongo::VERSION = '0.25';
4 3 ▶use MongoDB::OID;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 with('Mojito::Role::DB::Mongo');
10  
11 3 has base_url => ( is => 'rw', );
12  
13 =head1 Name
14  
15 Mojito::Page::CRUD::Mongo - MongoDB CRUD
16  
17 =head1 Methods
18  
19 =head2 create
20  
21 Create a page in the database.
22  
23 =cut
24  
25 0 ▶sub create {
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
26 0 my ( $self, $page_struct ) = @_;
27  
28 # Add created (and last_modified) timestamps
29 # If page struct has a created let's use that instead
30 # under the assumption we're loading outside data. e.g. from MojoMojo
31 0 my $now = time();
32 0 ▶ $page_struct->{created} //= $now;
Condition0%0/3
$page_struct->{"created"} //= $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$page_struct->{"created"} //= $now
$page_struct->{"created"} $now
Truth table0%0/3
A //= B
A= $page_struct->{"created"}B= $now
ABresult
1X1
011
000
33 0 ▶ $page_struct->{last_modified} //= $now;
Condition0%0/3
$page_struct->{"last_modified"} //= $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$page_struct->{"last_modified"} //= $now
$page_struct->{"last_modified"} $now
Truth table0%0/3
A //= B
A= $page_struct->{"last_modified"}B= $now
ABresult
1X1
011
000
34 0 my $id = $self->collection->insert($page_struct);
35  
36 0 return $id->value;
37 }
38  
39 =head2 read
40  
41 Read a page from the database.
42  
43 =cut
44  
45 0 ▶sub read {
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
46 0 my ( $self, $id ) = @_;
47 0 my $oid = MongoDB::OID->new( value => $id );
48 0 return $self->collection->find_one( { _id => $oid } );
49 }
50  
51 =head2 update
52  
53 Update a page in the database.
54  
55 =cut
56  
57 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
58 0 my ( $self, $id, $page_struct ) = @_;
59  
60 0 my $oid = MongoDB::OID->new( value => $id );
61 0 $page_struct->{last_modified} = time();
62 0 $self->collection->update( { '_id' => $oid }, $page_struct );
63 }
64  
65 =head2 delete
66  
67 Delete a page from the database.
68  
69 =cut
70  
71 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
72 0 my ( $self, $id ) = @_;
73  
74 0 my $oid = MongoDB::OID->new( value => $id );
75 0 $self->collection->remove( { '_id' => $oid } );
76 }
77  
78 =head2 get_all
79  
80 Get all pages in the notes collection.
81 Returns a MongoDB cursor one can iterate over.
82  
83 =cut
84  
85 0 ▶sub get_all {
Subroutine get_all: not called CC=1 SCAR=6.9
Pod documented
86 0 my $self = shift;
87 0 return $self->collection->find;
88 }
89  
90 3 1;
« Mojito/Filter/Shortcuts.pm ↑ Summary Mojito/Role/DB/Elasticsearch.pm »