Miril/Store/File/Post.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 74 CC 4 SCAR 12.5
CC
4
Cov
0%
body
6.0
teaser
6.0
status
6.0
CRAP 3.5
1 package Miril::Store::File::Post;
2
3 use strict;
4 use warnings;
5 use autodie;
6
7 use Try::Tiny;
8 use Miril::Exception;
9 use Miril::Filter::Markdown;
10 use File::Slurp;
11
12 use base 'Miril::Post';
13
14 use Object::Tiny qw(in_path);
15
16 sub body {
17 my $self = shift;
18
19 if ($self->{body}) {
20 return $self->{body};
21 } else {
22 $self->_populate;
23 return $self->{body};
24 }
25 }
26
27 sub teaser {
28 my $self = shift;
29
30 if ($self->{teaser}) {
31 return $self->{teaser};
32 } else {
33 $self->_populate;
34 return $self->{teaser};
35 }
36 }
37
38 sub status {
39 my $self = shift;
40 my $status = $self->published ? 'published' : 'draft';
41 return $status;
42 }
43
44 sub _populate {
45 my $self = shift;
46
47 my $post_file;
48 try {
49 $post_file = File::Slurp::read_file($self->in_path);
50 } catch {
51 Miril::Exception->throw(
52 message => "Cannot load data file",
53 errorvar => $_,
54 );
55 };
56
57 my ($meta, $source) = split( /\n\n/, $post_file, 2);
58 my ($teaser) = split( '<!-- BREAK -->', $source, 2);
59
60 # temporary until we introduce multiple filters
61 my $filter = Miril::Filter::Markdown->new;
62
63 $self->{body} = $filter->to_xhtml($source);
64 $self->{teaser} = $filter->to_xhtml($teaser);
65 $self->{source} = $source;
66 }
67
68 1;