Initial patch from Bruno for implementing a ::Storage::Format::XML
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Util.pm
index 6bdd02e..e11b33c 100644 (file)
@@ -4,7 +4,7 @@ use Moose qw(confess blessed);
 use MooseX::Storage::Engine ();
 use utf8 ();
 
-our $VERSION   = '0.17';
+our $VERSION   = '0.18';
 our $AUTHORITY = 'cpan:STEVAN';
 
 sub peek {
@@ -31,9 +31,8 @@ sub peek {
 
 sub _inflate_json {
     my ($class, $json) = @_;
-    
-    require JSON::Any;
-    eval { JSON::Any->import };
+
+    eval { require JSON::Any; JSON::Any->import };
     confess "Could not load JSON module because : $@" if $@; 
     
     utf8::encode($json) if utf8::is_utf8($json);    
@@ -65,6 +64,20 @@ sub _inflate_yaml {
     return $data;
 }
 
+sub _inflate_xml {
+    my ($class, $xml) = @_;
+    
+    eval { require XML::Simple; XML::Simple->import };
+    confess "Could not load XML::Simple module because : $@" if $@; 
+    
+    my $data = eval { XMLin($xml, SuppressEmpty => 1) };
+    if ($@) {
+        confess "There was an error when attempting to peek at XML: $@";
+    }
+    
+    return $data; 
+}
+
 1;
 
 __END__