Mojito/Page/CRUD/Elasticsearch.pm

filter: Statementstmt 34.2% 12 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 38.4% 20 / 52 CC 3 SCAR 15.5
CC
3
Cov
31%
read
12.0
create
2.0
update
2.0
CRAP 4.7
« Mojito/Template/Role/Javascript.pm ↑ Summary Mojito/Filter/Shortcuts.pm »
1 4 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mojito::Page::CRUD::Elasticsearch;
3 4 $Mojito::Page::CRUD::Elasticsearch::VERSION = '0.25';
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 with('Mojito::Role::DB::Elasticsearch');
8  
9 4 has base_url => ( is => 'rw', );
10  
11 =head1 Name
12  
13 Mojito::Page::CRUD::Elasticsearch - Elasticsearch CRUD
14  
15 =head1 Methods
16  
17 =head2 create
18  
19 Create a page in the database.
20  
21 =cut
22  
23 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
24 0 my ( $self, $page_struct ) = @_;
25 0 $page_struct->{last_modified} = $page_struct->{created} = time();
26 0 my $oid = $self->generate_mongo_like_oid;
27 0 $page_struct->{id} = $oid;
28 0 $self->db->index(
29 index => $self->db_name,
30 type => $self->collection_name,
31 id => $oid,
32 body => $page_struct,
33 );
34 0 return $oid;
35 }
36  
37 =head2 read
38  
39 Read a page from the database.
40  
41 =cut
42  
43  
44 0 ▶sub read {
Subroutine read: not called CC=3 SCAR=24.8
Pod documented
45 0 my ($self, $id) = @_;
46 0 ▶ die "No id passed" if !$id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
47  
48 0 my $doc;
49 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $doc = $self->db->get_source("index", $self->db_name, "type", $self->collection_name, "id", $id); 1 } }) 0 0 0
50 eval {
51 0 $doc = $self->db->get_source(
52 index => $self->db_name,
53 type => $self->collection_name,
54 id => $id,
55 0 ); 1;
56 }
57 ) {
58 0 warn "WARNING: Document with id: $id not found";
59 }
60  
61 0 return $doc;
62 }
63  
64 =head2 update
65  
66 Update a page in the database.
67  
68 =cut
69  
70 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
71 0 my ( $self, $id, $page_struct ) = @_;
72 0 $page_struct->{last_modified} = time();
73 # Add in id as a key/value
74 0 $page_struct->{id} = $id;
75 0 $self->db->update(
76 index => $self->db_name,
77 type => $self->collection_name,
78 id => $id,
79 body => { doc => $page_struct },
80 );
81 }
82  
83 =head2 delete
84  
85 Delete a page from the database.
86  
87 =cut
88  
89 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
90 0 my ( $self, $id ) = @_;
91 0 $self->db->delete(
92 index => $self->db_name,
93 type => $self->collection_name,
94 id => $id,
95 );
96 0 $self->db->indices->refresh( index => $self->db_name );
97 }
98  
99 =head2 get_all
100  
101 Get all pages in the notes collection.
102 Returns an ArrayRef
103  
104 =cut
105  
106 0 ▶sub get_all {
Subroutine get_all: not called CC=1 SCAR=6.9
Pod documented
107 0 my $self = shift;
108 0 return $self->collection->{hits}{hits};
109 }
110  
111 4 1
« Mojito/Template/Role/Javascript.pm ↑ Summary Mojito/Filter/Shortcuts.pm »