| 1 | 4 | ▶ | use strictures 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | package Mojito::Page::CRUD::Deep; | ||||||||||||||||||||||||||||
| 3 | 4 | $Mojito::Page::CRUD::Deep::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 | 4 | ▶ | use Data::Dumper::Concise; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | with('Mojito::Role::DB::Deep'); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | has base_url => ( is => 'rw', ); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 Name | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Mojito::Page::CRUD::Deep - DBM::Deep CRUD | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 Methods | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head2 create | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | Create a page in the database. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ( $self, $page_struct ) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # add save time as last_modified and created | ||||||||||||||||||||||||||||
| 28 | 0 | $page_struct->{last_modified} = $page_struct->{created} = time(); | |||||||||||||||||||||||||||
| 29 | 0 | my $oid = $self->generate_mongo_like_oid; | |||||||||||||||||||||||||||
| 30 | 0 | $page_struct->{id} = $oid; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Is this sucker used ja? | ||||||||||||||||||||||||||||
| 33 | # TODO: Seek out another when generated one is already used. | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | die "oid: $oid is already in use" if ($self->collection && $self->collection->exists($oid)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->collection and $self->collection->exists($oid)
MC/DC0%0/2
$self->collection and $self->collection->exists($oid)
$self->collection
$self->collection->exists($oid)
Truth table0%0/3
A and B
A= $self->collectionB= $self->collection->exists($oid)
| |||||||||||||||||||||||||||||
| 35 | # If the collection does not exist yet let's initialize it. | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (!$self->collection) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | $self->db->{$self->collection_name} = {}; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | $self->collection->{$oid} = $page_struct; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | return $oid; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head2 read | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Read a page from the database. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | die "No id passed" if !$id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($self->collection->{$id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | return $self->collection->{$id}->export; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head2 update | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Update a page in the database. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my ( $self, $id, $page_struct ) = @_; | |||||||||||||||||||||||||||
| 67 | 0 | $page_struct->{last_modified} = time(); | |||||||||||||||||||||||||||
| 68 | # Add in id as a key/value | ||||||||||||||||||||||||||||
| 69 | 0 | $page_struct->{id} = $id; | |||||||||||||||||||||||||||
| 70 | 0 | $self->collection->{$id} = $page_struct; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head2 delete | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Delete a page from the database. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 81 | 0 | $self->collection->delete($id); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head2 get_all | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Get all pages in the notes collection. | ||||||||||||||||||||||||||||
| 87 | Returns a MongoDB cursor one can iterate over. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub get_all { | ||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 0 | return $self->collection->export; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 4 | 1 | |||||||||||||||||||||||||||