lib/Rapi/Blog/Template/Dispatcher/Post.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 104 CC 3 SCAR 12.0
CC
3
Cov
0%
rank
6.0
resolved
6.0
BEGIN
2.0
CRAP 3.3
1 package Rapi::Blog::Template::Dispatcher::Post;
2 use strict;
3 use warnings;
4
5 use RapidApp::Util qw(:all);
6 use Rapi::Blog::Util;
7 use List::Util;
8
9 use Date::Parse;
10
11 use Moo;
12 extends 'Rapi::Blog::Template::Dispatcher';
13
14 use Types::Standard ':all';
15
16 has '+claimed', default => sub { 1 };
17 has '+restrict', default => sub { 1 };
18
19 has 'name', is => 'ro', required => 1, isa => Str;
20 has 'direct', is => 'ro', isa => Bool, default => sub { 0 };
21
22 sub rank { (shift)->direct ? 60 : 50 }
23
24
25 sub resolved {
26 my $self = shift;
27 $self->exists ? $self : $self->_factory_for('NotFound')
28 }
29
30 has 'PostRs', is => 'ro', init_arg => undef, lazy => 1, default => sub {
31 my $self = shift;
32 $self->AccessStore->Model->resultset('Post')->permission_filtered
33 };
34
35
36
37 has '_post_loaded', is => 'rw', isa => Bool, default => sub { 0 };
38 has 'Post', is => 'ro', init_arg => undef, lazy => 1, default => sub {
39 my $self = shift;
40 if(my $Row = $self->PostRs->search_rs({ 'me.name' => $self->name })->first) {
41 $self->_post_loaded(1);
42 return $Row
43 }
44 undef
45 };
46
47
48 has '+exists', default => sub {
49 my $self = shift;
50 return $self->Post ? 1 : 0 if ($self->_post_loaded);
51 $self->PostRs->search_rs({ 'me.name' => $self->name })->count ? 1 : 0
52 };
53
54 has '+mtime', default => sub {
55 my $self = shift;
56
57 my $Row = $self->_post_loaded ? $self->Post : $self->PostRs
58 ->search_rs(undef,{
59 columns => ['update_ts']
60 })
61 ->search_rs({ 'me.name' => $self->name })
62 ->first;
63
64 $Row ? Date::Parse::str2time( $Row->get_column('update_ts') ) : undef
65 };
66
67
68 has '+content', default => sub {
69 my $self = shift;
70
71 my $Row = $self->_post_loaded ? $self->Post : $self->PostRs
72 ->search_rs(undef,{
73 columns => ['body']
74 })
75 ->search_rs({ 'me.name' => $self->name })
76 ->first;
77
78 $Row ? $Row->get_column('body') : undef
79 };
80
81
82 has '+template_vars', default => sub {
83 my $self = shift;
84
85 my $data = {};
86 $data->{Row} = $data->{Post} = $self->Post if ($self->Post);
87
88 $data
89 };
90
91
92
93
94
95 1;