| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # WebFetch::Output::TT | 
| 2 |  |  |  |  |  |  | # ABSTRACT: save data from WebFetch via the Perl Template Toolkit | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # Copyright (c) 1998-2022 Ian Kluft. This program is free software; you can | 
| 5 |  |  |  |  |  |  | # redistribute it and/or modify it under the terms of the GNU General Public | 
| 6 |  |  |  |  |  |  | # License Version 3. See  https://www.gnu.org/licenses/gpl-3.0-standalone.html | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | # pragmas to silence some warnings from Perl::Critic | 
| 9 |  |  |  |  |  |  | ## no critic (Modules::RequireExplicitPackage) | 
| 10 |  |  |  |  |  |  | # This solves a catch-22 where parts of Perl::Critic want both package and use-strict to be first | 
| 11 | 1 |  |  | 1 |  | 1333 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 12 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 13 | 1 |  |  | 1 |  | 493 | use utf8; | 
|  | 1 |  |  |  |  | 13 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 14 |  |  |  |  |  |  | ## use critic (Modules::RequireExplicitPackage) | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | package WebFetch::Output::TT; | 
| 17 |  |  |  |  |  |  | $WebFetch::Output::TT::VERSION = '0.1.0'; | 
| 18 | 1 |  |  | 1 |  | 42 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 18 |  | 
| 19 | 1 |  |  | 1 |  | 4 | use base "WebFetch"; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 510 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 67684 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 48 |  | 
| 22 | 1 |  |  | 1 |  | 458 | use Template; | 
|  | 1 |  |  |  |  | 15975 |  | 
|  | 1 |  |  |  |  | 60 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # define exceptions/errors | 
| 25 |  |  |  |  |  |  | use Exception::Class ( | 
| 26 | 1 |  |  |  |  | 11 | "WebFetch::Output::TT::Exception::Template" => { | 
| 27 |  |  |  |  |  |  | isa => "WebFetch::TracedException", | 
| 28 |  |  |  |  |  |  | alias => "throw_template", | 
| 29 |  |  |  |  |  |  | description => "error during template processing", | 
| 30 |  |  |  |  |  |  | }, | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 1 |  |  | 1 |  | 8 | ); | 
|  | 1 |  |  |  |  | 2 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # set defaults | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | our @Options = ( "template=s", "tt_include:s" ); | 
| 38 |  |  |  |  |  |  | our $Usage = "--template template-file [--tt_include include-path]"; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | # no user-servicable parts beyond this point | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # register capabilities with WebFetch | 
| 43 |  |  |  |  |  |  | __PACKAGE__->module_register( "cmdline", "output:tt" ); | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # Perl Template Toolkit format handler | 
| 47 |  |  |  |  |  |  | sub fmt_handler_tt | 
| 48 |  |  |  |  |  |  | { | 
| 49 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 50 | 0 |  |  |  |  |  | my $filename = shift; | 
| 51 | 0 |  |  |  |  |  | my $output; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # configure and create template object | 
| 54 | 0 |  |  |  |  |  | my %tt_config = ( | 
| 55 |  |  |  |  |  |  | ABSOLUTE => 1, | 
| 56 |  |  |  |  |  |  | RELATIVE => 1, | 
| 57 |  |  |  |  |  |  | ); | 
| 58 | 0 | 0 |  |  |  |  | if ( exists $self->{tt_include}) { | 
| 59 |  |  |  |  |  |  | $tt_config{INCLUDE_PATH} = $self->{tt_include} | 
| 60 | 0 |  |  |  |  |  | } | 
| 61 | 0 |  |  |  |  |  | my $template = Template->new( \%tt_config ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | # process template | 
| 64 |  |  |  |  |  |  | $template->process( $self->{template}, { data => $self->{data}}, | 
| 65 | 0 | 0 |  |  |  |  | \$output, { binmode => ':utf8'} ) | 
| 66 |  |  |  |  |  |  | or throw_template $template->error(); | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 0 |  |  |  |  |  | $self->raw_savable( $filename, $output ); | 
| 69 | 0 |  |  |  |  |  | return 1; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =pod | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =encoding UTF-8 | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 NAME | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | WebFetch::Output::TT - save data from WebFetch via the Perl Template Toolkit | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head1 VERSION | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | version 0.1.0 | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | In perl scripts: | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | C | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | From the command line: | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | C | 
| 95 |  |  |  |  |  |  | [...WebFetch input options...] --dir directory | 
| 96 |  |  |  |  |  |  | --dest_format tt --dest dest-path --template tt-file > | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | This module saves output via the Perl Template Toolkit. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =over 4 | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =item $obj->fmt_handler_tt( $filename ) | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | This function formats the data according to the Perl Template Toolkit | 
| 107 |  |  |  |  |  |  | template provided in the --template parameter. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =back | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | L | 
| 114 |  |  |  |  |  |  | L | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head1 BUGS AND LIMITATIONS | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Please report bugs via GitHub at L | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | Patches and enhancements may be submitted via a pull request at L | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head1 AUTHOR | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | Ian Kluft | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | This software is Copyright (c) 1998-2022 by Ian Kluft. | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | This is free software, licensed under: | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | The GNU General Public License, Version 3, June 2007 | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =cut | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | __END__ |