| 1 | package Grimlock::Web::Controller::Entry; | ||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||
| 3 | 4 | $Grimlock::Web::Controller::Entry::VERSION = '0.11'; | |||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | BEGIN {extends 'Grimlock::Web::Controller::API'; } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | Grimlock::Web::Controller::Entry - Catalyst Controller | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | Catalyst Controller. | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | sub base : Chained('/api/base') PathPart('') CaptureArgs(0) {} | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
base: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | sub load_entry : Chained('base') PathPart('') CaptureArgs(1) { | ||||||||||||||||||||||||||||||||
|
Subroutine
load_entry: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 27 | 4 | my ( $self, $c, $entry_title ) = @_; | |||||||||||||||||||||||||||||||||
| 28 | 4 | my $entry = $c->model('Database::Entry')->find( | |||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||
| 30 | display_title => $entry_title | ||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||
| 33 | prefetch => 'children' | ||||||||||||||||||||||||||||||||||
| 34 | }); | ||||||||||||||||||||||||||||||||||
| 35 | 4 | $c->stash( entry => $entry ); | |||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub create : Chained('base') PathPart('entry') Args(0) ActionClass('REST') { | ||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub create_GET { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_GET: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unless ( $c->user_exists ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | return $self->status_bad_request($c, | |||||||||||||||||||||||||||||||||
| 47 | message => "You must be logged in to create an entry" | ||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||
| 50 | 0 | my $user = $c->user; | |||||||||||||||||||||||||||||||||
| 51 | 0 | $self->status_ok( $c, entity => {} ); | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub create_POST { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_POST: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 55 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | unless ( $c->user_exists ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | 1 | return $self->status_bad_request($c, | |||||||||||||||||||||||||||||||||
| 58 | message => "You must be logged in to create an entry" | ||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | my $params = $c->req->data || $c->req->params; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c->req->data || $c->req->params
MC/DC0%0/2
$c->req->data || $c->req->params
$c->req->data
$c->req->params
Truth table33%1/3
A || B
A= $c->req->dataB= $c->req->params
| |||||||||||||||||||||||||||||||||||
| 63 | 1 | my $user = $c->user->obj; | |||||||||||||||||||||||||||||||||
| 64 | 1 | my $entry; | |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | $params->{'published'} = 1 if $params->{'published'} eq 'on'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | $entry = $user->create_entry($params) || die $!; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$user->create_entry($params) || die($!)
MC/DC0%0/1
$user->create_entry($params) || die($!)
$user->create_entry($params)
Truth table50%1/2
A
A= $user->create_entry($params)
| |||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 1 | $self->status_created($c, | |||||||||||||||||||||||||||||||||
| 70 | location => $c->req->uri->as_string, | ||||||||||||||||||||||||||||||||||
| 71 | entity => { | ||||||||||||||||||||||||||||||||||
| 72 | message => "Entry created!", | ||||||||||||||||||||||||||||||||||
| 73 | entry => $entry | ||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | return $self->status_bad_request($c, | |||||||||||||||||||||||||||||||||
| 78 | message => $_ | ||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||
| 80 | 1 | }; | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub reply : Chained('load_entry') PathPart('reply') Args(0) ActionClass('REST') { | ||||||||||||||||||||||||||||||||
|
Subroutine
reply: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 84 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub reply_GET { | ||||||||||||||||||||||||||||||||
|
Subroutine
reply_GET: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 88 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 89 | 0 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return $self->status_bad_request($c, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 91 | message => "No such post" | ||||||||||||||||||||||||||||||||||
| 92 | ) unless $entry; | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | return $self->status_ok($c, | |||||||||||||||||||||||||||||||||
| 95 | entity => { | ||||||||||||||||||||||||||||||||||
| 96 | entry => $entry | ||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub reply_POST { | ||||||||||||||||||||||||||||||||
|
Subroutine
reply_POST: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 102 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | my $params ||= $c->req->data || $c->req->params; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
my $params ||= $c->req->data || $c->req->params
$c->req->data || $c->req->params
MC/DC0%0/3
my $params ||= $c->req->data || $c->req->params
my $params
$c->req->data
$c->req->params
Truth table0%0/4
A ||= B || C
A= my $paramsB= $c->req->dataC= $c->req->params
| |||||||||||||||||||||||||||||||||||
| 104 | 2 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | return $self->status_bad_request($c, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | message => "No such post" | ||||||||||||||||||||||||||||||||||
| 107 | ) unless $entry; | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 2 | my $reply; | |||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 2 | my $title = "RE:" . $entry->title . rand; | |||||||||||||||||||||||||||||||||
| 113 | 2 | $c->log->debug("REPLY $title"); | |||||||||||||||||||||||||||||||||
| 114 | $reply = $c->model('Database::Entry')->create({ | ||||||||||||||||||||||||||||||||||
| 115 | author => $c->user->obj->userid, | ||||||||||||||||||||||||||||||||||
| 116 | parent => $entry, | ||||||||||||||||||||||||||||||||||
| 117 | title => $title, | ||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | body => $params->{'body'}, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | published => 1, | ||||||||||||||||||||||||||||||||||
| 120 | }) or die $!; | ||||||||||||||||||||||||||||||||||
| 121 | 2 | return $self->status_created($c, | |||||||||||||||||||||||||||||||||
| 122 | location => $c->uri_for_action('/entry/browse', [ $reply->display_title ] ), | ||||||||||||||||||||||||||||||||||
| 123 | entity => { | ||||||||||||||||||||||||||||||||||
| 124 | message => "Reply posted!", | ||||||||||||||||||||||||||||||||||
| 125 | reply => $reply, | ||||||||||||||||||||||||||||||||||
| 126 | entry => $reply->parent | ||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | return $self->status_bad_request($c, | |||||||||||||||||||||||||||||||||
| 131 | message => $_ | ||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||
| 133 | 2 | }; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | sub browse : Chained('load_entry') PathPart('') Args(0) ActionClass('REST') { | ||||||||||||||||||||||||||||||||
|
Subroutine
browse: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 138 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 139 | 2 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | return $self->status_bad_request($c, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | message => "No such post" | ||||||||||||||||||||||||||||||||||
| 142 | ) unless $entry; | ||||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | sub browse_GET { | ||||||||||||||||||||||||||||||||
|
Subroutine
browse_GET: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 146 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 147 | 1 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 148 | 1 | return $self->status_ok($c, | |||||||||||||||||||||||||||||||||
| 149 | entity => { | ||||||||||||||||||||||||||||||||||
| 150 | entry => $entry | ||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub browse_PUT { | ||||||||||||||||||||||||||||||||
|
Subroutine
browse_PUT: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 157 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 158 | 0 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $params ||= $c->req->data || $c->req->params; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
my $params ||= $c->req->data || $c->req->params
$c->req->data || $c->req->params
MC/DC0%0/3
my $params ||= $c->req->data || $c->req->params
my $params
$c->req->data
$c->req->params
Truth table0%0/4
A ||= B || C
A= my $paramsB= $c->req->dataC= $c->req->params
| |||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $params->{'published'} = $params->{'published'} eq 'on' ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 0 | delete $params->{$_} for qw( frmInsertFlag frmRecord ); | |||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $entry->update($params) || return $self->status_bad_request($c, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | message => "Couldn't update entry; $!" | ||||||||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | 0 | return $self->status_ok($c, | |||||||||||||||||||||||||||||||||
| 167 | entity => { | ||||||||||||||||||||||||||||||||||
| 168 | entry => $entry | ||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | sub browse_DELETE { | ||||||||||||||||||||||||||||||||
|
Subroutine
browse_DELETE: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 174 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||
| 175 | 1 | my $entry = $c->stash->{'entry'}; | |||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | $entry->delete || return $self->status_bad_request($c, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 177 | message => "Couldn't delete entry: $!" | ||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | 1 | return $self->status_ok($c, | |||||||||||||||||||||||||||||||||
| 181 | entity => { | ||||||||||||||||||||||||||||||||||
| 182 | deleted => 1 | ||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | Devin Austin | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||
| 198 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | 4 | 1; | |||||||||||||||||||||||||||||||||