HiD/Generator/ArchivePage.pm

filter: Statementstmt 34.2% 13 / 38 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 30.9% 17 / 55 CC 6 SCAR 33.4
CC
6
Cov
28%
generate
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« HiD/Generator/AtomFeed.pm ↑ Summary HiD/Generator/TagPages.pm »
1 # ABSTRACT: Archive page generator
2  
3  
4 package HiD::Generator::ArchivePage;
5 1 our $AUTHORITY = 'cpan:GENEHACK';
6 1 $HiD::Generator::ArchivePage::VERSION = '1.96';
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 with 'HiD::Generator';
9  
10 1 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use HiD::Page;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub generate {
16 0 ▶ my( $self , $site ) = @_;
Subroutine generate: not called CC=6 SCAR=37.4
Pod documented
17  
18 0 ▶ return unless $site->config->{archive_page}{generate};
Branch: 1 branch
BranchTrueFalseTotal
unless $site->config->{"archive_page"}{"generate"} 0 0 0
19  
20 my $input_file = $site->config->{archive_page}{layout}
21 0 ▶ or die "Must define archive_page.layout in config if archive_page.generate is enabled";
Branch: 1 branch
BranchTrueFalseTotal
my $input_file = $site->config->{"archive_page"}{"layout"} or die "Must define archive_page.layout in config if archive_page.generate is enabled" 0 0 0
22  
23 0 ▶ my $url = $site->config->{archive_page}{url} // 'archive/';
Condition0%0/2
$site->config->{"archive_page"}{"url"} // "archive/"
l!l
00
MC/DC0%0/1
$site->config->{"archive_page"}{"url"} // "archive/"
$site->config->{"archive_page"}{"url"}
Truth table0%0/2
A
A= $site->config->{"archive_page"}{"url"}
Aresult
11
00
24  
25 0 ▶ my $destination = $site->config->{archive_page}{destination} // $site->destination;
Condition0%0/3
$site->config->{"archive_page"}{"destination"} // $site->destination
l!l&&r!l&&!r
000
MC/DC0%0/2
$site->config->{"archive_page"}{"destination"} // $site->destination
$site->config->{"archive_page"}{"destination"} $site->destination
Truth table0%0/3
A // B
A= $site->config->{"archive_page"}{"destination"}B= $site->destination
ABresult
1X1
011
000
26  
27 0 $self->_create_destination_directory_if_needed( $destination );
28  
29 0 my %archive = (
30 by_year => {} ,
31 by_year_month => {} ,
32 );
33  
34 0 foreach my $post ( @{ $site->posts } ) {
35 0 push @{ $archive{by_year}{ $post->year() }} , $post;
36  
37 0 my $year_month = sprintf "%4d%02d" , $post->year() , $post->month();
38 0 push @{ $archive{by_year_month}{$year_month} } , $post;
39 }
40  
41 0 $archive{sorted_years} = [ sort { $b <=> $a } keys %{ $archive{by_year} } ];
42 0 $archive{sorted_year_monthss} = [ sort { $b <=> $a } keys %{ $archive{by_year_month} } ];
43  
44 0 my $page = HiD::Page->new({
45 dest_dir => $destination ,
46 hid => $site ,
47 url => $url ,
48 input_filename => $input_file ,
49 layouts => $site->layouts ,
50 });
51 0 $page->metadata->{archive} = \%archive;
52  
53 0 $site->add_input( "Archives" => 'page' );
54 0 $site->add_object( $page );
55  
56 0 $site->INFO( "* Injected Archive page");
57 }
58  
59 1 __PACKAGE__->meta->make_immutable;
60 1 1;
61  
62 __END__
63  
64 =pod
65  
66 =encoding UTF-8
67  
68 =head1 NAME
69  
70 HiD::Generator::ArchivePage - Archive page generator
71  
72 =head1 DESCRIPTION
73  
74 This Generator produces an archive page of all your posts.
75  
76 Enable it by setting the 'archive_page.generate' key in your config to true
77 and the 'archive_page.layout' key to the path with the layout for the archive
78 page. You can also set 'archive_page.url' to the URL where the page should be
79 published to, or let it default to the site-wide destination. Finally,
80 'archive_page.destination' can be used to set a destination directory.
81  
82 =head1 METHODS
83  
84 =head2 generate
85  
86 =head1 VERSION
87  
88 version 1.96
89  
90 =head1 AUTHOR
91  
92 John SJ Anderson <genehack@genehack.org>
93  
94 =head1 COPYRIGHT AND LICENSE
95  
96 This software is copyright (c) 2015 by John SJ Anderson.
97  
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100  
101 =cut
« HiD/Generator/AtomFeed.pm ↑ Summary HiD/Generator/TagPages.pm »