| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 56616 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 48 |  | 
| 2 |  |  |  |  |  |  | package Template::Plugin::YAML; | 
| 3 | 1 |  |  | 1 |  | 706 | use Template::Plugin; | 
|  | 1 |  |  |  |  | 534 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 4 | 1 |  |  | 1 |  | 15 | use base 'Template::Plugin'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 54 |  | 
| 5 | 1 |  |  | 1 |  | 8 | use YAML qw(Dump Load DumpFile LoadFile); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 79 |  | 
| 6 | 1 |  |  | 1 |  | 4 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 274 |  | 
| 7 |  |  |  |  |  |  | $VERSION = '1.23'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Template::Plugin::YAML - Plugin interface to YAML | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | [% USE YAML %] | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | [% YAML.dump(variable) %] | 
| 18 |  |  |  |  |  |  | [% YAML.dump_html(variable) %] | 
| 19 |  |  |  |  |  |  | [% value = YAML.undump(yaml_string) %] | 
| 20 |  |  |  |  |  |  | [% YAML.dumpfile(filename, variable) %] | 
| 21 |  |  |  |  |  |  | [% value = YAML.undumpfile(filename) %] | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | This is a simple Template Toolkit Plugin Interface to the YAML module. | 
| 26 |  |  |  |  |  |  | A YAML object will be instantiated via the following directive: | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | [% USE YAML %] | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | As a standard plugin, you can also specify its name in lower case: | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | [% USE yaml %] | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 METHODS | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | These are the methods supported by the YAML object. | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head2 dump( @variables ) | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Generates a raw text dump of the data structure(s) passed | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | [% USE Dumper %] | 
| 43 |  |  |  |  |  |  | [% yaml.dump(myvar) %] | 
| 44 |  |  |  |  |  |  | [% yaml.dump(myvar, yourvar) %] | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub dump { | 
| 49 | 1 |  |  | 1 | 1 | 68 | my $self = shift; | 
| 50 | 1 |  |  |  |  | 4 | my $content = Dump @_; | 
| 51 | 1 |  |  |  |  | 14167 | return $content; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head2 dump_html( @variables ) | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Generates a dump of the data structures, as per C, but with the | 
| 58 |  |  |  |  |  |  | characters E, E and E converted to their equivalent HTML | 
| 59 |  |  |  |  |  |  | entities, spaces converted to   and newlines converted to | 
| 60 |  |  |  |  |  |  | EbrE. | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | [% USE yaml %] | 
| 63 |  |  |  |  |  |  | [% yaml.dump_html(myvar) %] | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =cut | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub dump_html { | 
| 68 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 69 | 0 |  |  |  |  |  | my $content = Dump @_; | 
| 70 | 0 |  |  |  |  |  | for ($content) { | 
| 71 | 0 |  |  |  |  |  | s/&/&/g; | 
| 72 | 0 |  |  |  |  |  | s/ / /g; | 
| 73 | 0 |  |  |  |  |  | s/</g; | 
| 74 | 0 |  |  |  |  |  | s/>/>/g; | 
| 75 | 0 |  |  |  |  |  | s/\n/ \n/g;
 | 
| 76 |  |  |  |  |  |  | } | 
| 77 | 0 |  |  |  |  |  | return $content; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head2 undump( $string ) | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Converts a YAML-encoded string into the equivalent data structure. | 
| 84 |  |  |  |  |  |  | Here's a way to deep-copy a complex structure by completely serializing | 
| 85 |  |  |  |  |  |  | the data. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | [% USE yaml; | 
| 88 |  |  |  |  |  |  | yaml_string = yaml.dump(complex_data_structure); | 
| 89 |  |  |  |  |  |  | complex_copy = yaml.undump(yaml_string); | 
| 90 |  |  |  |  |  |  | %] | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =cut | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub undump { | 
| 95 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 96 | 0 |  |  |  |  |  | return Load shift; | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head2 dumpfile( $file, @variables ) | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | Converts the data to YAML encoding, and dumps it to the specified | 
| 103 |  |  |  |  |  |  | filepath. | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | [% USE yaml; yaml.dumpfile(".storage", my_data) %] | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =cut | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub dumpfile { | 
| 110 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 111 | 0 |  |  |  |  |  | return DumpFile @_; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head2 undumpfile( $file ) | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | Loads the YAML-encoded data from the specified filepath | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | [% USE yaml; my_data = yaml.undumpfile(".storage") %] | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =cut | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | sub undumpfile { | 
| 124 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 125 | 0 |  |  |  |  |  | return LoadFile @_; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | 1; | 
| 129 |  |  |  |  |  |  | __END__ |