| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/env perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =pod | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | wrt-render-all - utility for rendering static HTML files from wrt entries | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 USAGE | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | wrt render-all | 
| 12 |  |  |  |  |  |  | wrt render-all --config ./wrt.json ... | 
| 13 |  |  |  |  |  |  | wrt render-all --help | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Renders all entries in the current wrt archive to the C specified | 
| 18 |  |  |  |  |  |  | in the configuration file (normally F).  By default, this is | 
| 19 |  |  |  |  |  |  | F<./public>. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Detailed documentation can be found in the L man page or at | 
| 22 |  |  |  |  |  |  | L. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head1 LICENSE | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | wrt is free software; you can redistribute it and/or modify | 
| 27 |  |  |  |  |  |  | it under the terms of the GNU General Public License as published by | 
| 28 |  |  |  |  |  |  | the Free Software Foundation; either version 2 of the License, or | 
| 29 |  |  |  |  |  |  | (at your option) any later version. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =head1 AUTHOR | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | Brennen Bearnes   | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =cut | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 1 |  |  | 1 |  | 500 | use 5.10.0; | 
|  | 1 |  |  |  |  | 3 |  | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 53 |  | 
| 40 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 41 | 1 |  |  | 1 |  | 4 | no  warnings 'uninitialized'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 56 |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 1 |  |  | 1 |  | 707 | use Getopt::Long; | 
|  | 1 |  |  |  |  | 10679 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 44 | 1 |  |  | 1 |  | 658 | use Pod::Usage; | 
|  | 1 |  |  |  |  | 38395 |  | 
|  | 1 |  |  |  |  | 126 |  | 
| 45 | 1 |  |  | 1 |  | 653 | use Time::HiRes; | 
|  | 1 |  |  |  |  | 1357 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 46 | 1 |  |  | 1 |  | 509 | use App::WRT; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 47 | 1 |  |  | 1 |  | 7 | use App::WRT::FileIO; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 48 | 1 |  |  | 1 |  | 465 | use App::WRT::Renderer; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 258 |  | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | my $start_time = [Time::HiRes::gettimeofday()]; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | # If invoked directly from the command-line, caller() will return undef. | 
| 53 |  |  |  |  |  |  | # Execute main() with a callback to print output directly, a FileIO object, | 
| 54 |  |  |  |  |  |  | # and a copy of our real @ARGV: | 
| 55 |  |  |  |  |  |  | if (not caller()) { | 
| 56 |  |  |  |  |  |  | my $output = sub { say @_; }; | 
| 57 |  |  |  |  |  |  | my $io = App::WRT::FileIO->new(); | 
| 58 |  |  |  |  |  |  | main($output, $io, @ARGV); | 
| 59 |  |  |  |  |  |  | exit(0); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | # main() takes an output callback, a FileIO object or equivalent, and an @ARGV | 
| 63 |  |  |  |  |  |  | # to pass in to GetOptionsFromArray().  This allows relatively simple | 
| 64 |  |  |  |  |  |  | # integration tests to be written.  See also: t/bin-wrt-render-all.t | 
| 65 |  |  |  |  |  |  | sub main { | 
| 66 | 1 |  |  | 1 |  | 7 | my ($output, $io, @local_argv) = @_; | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | # Handle options, including help generated from the POD above.  See: | 
| 69 |  |  |  |  |  |  | # - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options | 
| 70 |  |  |  |  |  |  | # - https://metacpan.org/pod/Pod::Usage | 
| 71 |  |  |  |  |  |  | # - http://michael.thegrebs.com/2014/06/08/Pod-Usage/ | 
| 72 | 1 |  |  |  |  | 2 | my $config_file = 'wrt.json'; | 
| 73 |  |  |  |  |  |  | GetOptions( | 
| 74 |  |  |  |  |  |  | 'config=s' => \$config_file, | 
| 75 | 0 |  |  | 0 |  | 0 | help       => sub { pod2usage(0) }, | 
| 76 | 1 | 50 |  |  |  | 6 | ) or pod2usage(2); | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 1 | 50 |  |  |  | 306 | unless (-e $config_file) { | 
| 79 | 0 |  |  |  |  | 0 | die "No wrt config file found.  Tried: $config_file"; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 1 |  |  |  |  | 6 | my $wrt = App::WRT::new_from_file($config_file); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | # This expects a callback to handle logging output and a callback to handle | 
| 85 |  |  |  |  |  |  | # file writing: | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 1 |  |  |  |  | 28 | my $renderer = App::WRT::Renderer->new( | 
| 88 |  |  |  |  |  |  | $wrt, | 
| 89 |  |  |  |  |  |  | $output, | 
| 90 |  |  |  |  |  |  | $io | 
| 91 |  |  |  |  |  |  | ); | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 1 |  |  |  |  | 7 | $renderer->render(); | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 1 |  |  |  |  | 8 | $output->( | 
| 96 |  |  |  |  |  |  | "elapsed: " . Time::HiRes::tv_interval($start_time) . " seconds" | 
| 97 |  |  |  |  |  |  | ); | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | 1; |