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