Untested, but here goes:

--- YAML.pm~    2003-07-30 15:38:45.000000000 -0700
+++ YAML.pm     2003-08-27 08:47:19.000000000 -0700
@@ -2,11 +2,10 @@
 package Template::Plugin::YAML;
 use Template::Plugin;
 use base 'Template::Plugin';
-use YAML qw(Dump);
+use YAML qw(Dump Load DumpFile LoadFile);
 use vars qw($VERSION);
 $VERSION = 1.21;
 
-# any resemblance to Template::Plugin::Dumper is because we stole it all
 sub dump {
     my $self = shift;
     my $content = Dump @_;
@@ -26,6 +25,21 @@
     return $content;
 }
 
+sub load {
+  my $self = shift;
+  return Load @_;
+}
+
+sub dumpfile {
+  my $self = shift;
+  return DumpFile @_;
+}
+
+sub loadfile {
+  my $self = shift;
+  return LoadFile @_;
+}
+
 1;
 __END__
 
@@ -39,6 +53,9 @@
 
     [% YAML.dump(variable) %]
     [% YAML.dump_html(variable) %]
+    [% value = YAML.load(yaml_string) %]
+    [% YAML.dumpfile(filename, variable) %]
+    [% value = YAML.loadfile(filename) %]
 
 =head1 DESCRIPTION
 
@@ -54,9 +71,7 @@
 
 =head1 METHODS
 
-There are two methods supported by the YAML object.  Each will
-output into the template the contents of the variables passed to the
-object method.
+There are five methods supported by the YAML object.
 
 =head2 dump()
 
@@ -77,9 +92,34 @@
     [% USE yaml %]
     [% yaml.dump_html(myvar) %]
 
+=head2 load()
+
+Converts a YAML-encoded string into the equivalent data structure.
+Here's a way to deep-copy a complex structure by completely serializing
+the data.
+
+  [% USE yaml;
+     yaml_string = yaml.dump(complex_data_structure);
+     complex_copy = yaml.load(yaml_string);
+  %]
+
+=head2 dumpfile()
+
+Converts the data to YAML encoding, and dumps it to the specified
+filepath.
+
+  [% USE yaml; yaml.dumpfile(".storage", my_data) %]
+
+=head2 loadfile()
+
+Loads the YAML-encoded data from the specified filepath
+
+  [% USE yaml; my_data = yaml.loadfile(".storage") %]
+
 =head1 AUTHOR
 
-Richard Clamp <[EMAIL PROTECTED]>
+Richard Clamp <[EMAIL PROTECTED]>, with help from
+Randal L. Schwartz <[EMAIL PROTECTED]>
 
 based on Simon Matthews' L<Template::Plugin::Dumper>
 

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to