HiD/Page.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 8 / 8 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 96.4% 82 / 85 CC 7 SCAR 10.2
CC
7
Cov
99%
_build_url
6.0
publish
2.0
BEGIN
1.0
CRAP 2.8
« HiD/Post.pm ↑ Summary HiD/App/Command/init.pm »
1 # ABSTRACT: Pages that are converted during the output process
2  
3  
4 package HiD::Page;
5 21 our $AUTHORITY = 'cpan:GENEHACK';
6 21 $HiD::Page::VERSION = '1.96';
7 21 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 with 'HiD::Role::IsConverted';
9 21 with 'HiD::Role::IsPublished';
10 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 21 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use warnings qw/ FATAL utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use open qw/ :std :utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use charnames qw/ :full /;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 21 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 24 ▶sub get_default_layout { 'default' }
Subroutine get_default_layout: called CC=1 SCAR=0.0
Pod documented
23  
24  
25 sub publish {
26 31 ▶ my $self = shift;
Subroutine publish: called CC=2 SCAR=6.9
Pod documented
27  
28 31 my $out = path( $self->output_filename );
29 31 my $dir = $out->parent;
30  
31 31 ▶ $dir->mkpath unless $dir->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->is_dir 2 29 31
32  
33 31 $out->spew_utf8( $self->rendered_content );
34 }
35  
36 # used to populate the 'url' attr in Role::IsPublished
37 sub _build_url {
38 31 ▶ my $self = shift;
Subroutine _build_url: called CC=6 SCAR=17.9
39  
40 31 ▶ my $format = $self->get_metadata( 'permalink' ) // 'none';
Condition100%2/2
$self->get_metadata("permalink") // "none"
l!l
724
MC/DC100%1/1
$self->get_metadata("permalink") // "none"
$self->get_metadata("permalink")
Truth table100%2/2
A
A= $self->get_metadata("permalink")
Aresult
11
00
41  
42 31 my $source = $self->source;
43  
44 31 my $path_frag = $self->input_path;
45 31 $path_frag =~ s/^$source//;
46 31 ▶ $path_frag ||= Path::Tiny->rootdir();
Condition66%2/3
$path_frag ||= "Path::Tiny"->rootdir
l!l&&r!l&&!r
2650
MC/DC0%0/2
$path_frag ||= "Path::Tiny"->rootdir
$path_frag "Path::Tiny"->rootdir
Truth table66%2/3
A ||= B
A= $path_fragB= "Path::Tiny"->rootdir
ABresult
1X1
011
000
47  
48 31 my $naive = path( $path_frag , $self->basename() );
49  
50 31 my %_valid_exts = map { $_=>1 } qw(rss xml html htm xhtml xhtm shtml shtm);
51 31 ▶ my $ext = exists $_valid_exts{$self->ext} ? $self->ext : 'html';
Branch: 1 branch
BranchTrueFalseTotal
exists $_valid_exts{$self->ext} ? : 10 21 31
52  
53 31 my $url;
54  
55 31 ▶ if( $format eq 'none' ) { $url = $naive . ".$ext" }
Branch: 2 branches
BranchTrueFalseTotal
if ($format eq 'none') { } 24 7 31
elsif ($format eq 'pretty') { } 1 6 7
56 1 elsif( $format eq 'pretty' ) { $url = $naive . '/' }
57 6 else { $url = "/$format" }
58  
59 31 $url =~ s|//+|/|g;
60  
61 31 return $url;
62 }
63  
64 21 __PACKAGE__->meta->make_immutable;
65 21 1;
66  
67 __END__
68  
69 =pod
70  
71 =encoding UTF-8
72  
73 =head1 NAME
74  
75 HiD::Page - Pages that are converted during the output process
76  
77 =head1 SYNOPSIS
78  
79 my $page = HiD::Page->new({
80 dest_dir => 'path/to/output/dir' ,
81 hid => $hid_object ,
82 input_filename => 'path/to/page/file' ,
83 layouts => $hash_of_hid_layout_objects,
84 });
85  
86 =head1 DESCRIPTION
87  
88 Class representing a "page" object -- i.e., a file that is not a blog post,
89 but that is still processed (e.g., converted from Markdown or Textile to HTML
90 and run through a layout rendering step) during publication.
91  
92 =head1 METHODS
93  
94 =head2 get_default_layout
95  
96 Get the name of the default page layout. (The default is 'default'.)
97  
98 =head2 publish
99  
100 Publish -- convert, render through any associated layouts, and write out to
101 disk -- this data from this object.
102  
103 =head1 NOTE
104  
105 Also consumes L<HiD::Role::IsConverted> and L<HiD::Role::IsPublished>; see
106 documentation for that role as well if you're trying to figure out how an
107 object from this class works.
108  
109 =head1 VERSION
110  
111 version 1.96
112  
113 =head1 AUTHOR
114  
115 John SJ Anderson <genehack@genehack.org>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is copyright (c) 2015 by John SJ Anderson.
120  
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123  
124 =cut
« HiD/Post.pm ↑ Summary HiD/App/Command/init.pm »