HiD/Generator/TagPages.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 34 CC 2 SCAR 13.9
CC
2
Cov
0%
generate
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 4.0
1 # ABSTRACT: Example generator to create tagged pages
2  
3  
4 package HiD::Generator::TagPages;
5 $HiD::Generator::TagPages::VERSION = '1.5';
6 use Moose;
7 with 'HiD::Generator';
8  
9 use HiD::Page;
10  
11 has 'destination' => (
12 is => 'ro' ,
13 isa => 'HiD_DirPath' ,
14 );
15  
16  
17 sub generate {
18 my( $self , $site ) = @_;
19  
20 return unless $site->config->{tags}{generate};
21  
22 my $input_file = $site->config->{tags}{input}
23 or die "Must define tags.layout in config if tags.generate is enabled";
24  
25 my $destination = $self->destination // $site->destination;
26  
27 foreach my $tag ( keys %{ $site->tags } ) {
28 my $page = HiD::Page->new({
29 dest_dir => $destination ,
30 hid => $site ,
31 url => "tags/$tag/" ,
32 input_filename => $input_file ,
33 layouts => $site->layouts ,
34 });
35 $page->metadata->{tag} = $tag;
36  
37 $site->add_input( "Tag_$tag" => 'page' );
38 $site->add_object( $page );
39  
40 $site->INFO( "* Injected tag page for '$tag'");
41 }
42 }
43  
44 __PACKAGE__->meta->make_immutable;
45 1;
46  
47 __END__
48  
49 =pod
50  
51 =encoding utf-8
52  
53 =head1 NAME
54  
55 HiD::Generator::TagPages - Example generator to create tagged pages
56  
57 =head1 DESCRIPTION
58  
59 This is an example of a generator plugin. It generates one page per key in the
60 C<< $site->tags >> hash, and injects that page into the site so that it will
61 be published.
62  
63 This plugin can be used with minimal work on your part by enabling the
64 required options in your cnofiguration and putting a file like the following
65 example into the C<_plugins> directory of your site:
66  
67 package Tags;
68 use Moose;
69 extends 'HiD::Generator::TagPages';
70  
71 # you override the default destination like so
72 has '+destination' => ( default => '_site/subdir' );
73  
74 __PACKAGE__->meta->make_immutable;
75 1;
76  
77 As shown above, you can control where the resulting pages are generated by
78 overridding the C<destination> attribute. If you want to tweak more than that,
79 you're probably better off just copying the whole module into your C<_plugins>
80 directory and modifying it directly.
81  
82 =head1 METHODS
83  
84 =head2 generate
85  
86 =head1 VERSION
87  
88 version 1.5
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) 2014 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