Commits

Anonymous committed 45070e5

Add the 'dom' argument to 'source' (with a test).

  • Participants
  • Parent commits 8bdc0ac

Comments (0)

Files changed (2)

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Fiction/ToHTML.pm

 
 =item * my $xhtml_source = $converter->translate_to_html({source => {string_ref => \$buffer}, output => "string" })
 
-=item * my $xhtml_dom = $converter->translate_to_html({source => {file => $filename}, output => "xml" })
+=item * my $xhtml_dom = $converter->translate_to_html({source => {file => $filename}, output => "dom" })
+
+=item * my $xhtml_dom = $converter->translate_to_html({source => {dom => $libxml_dom}, output => "dom" })
 
 =back
 
 keys and values for the source. If C<'file'> is specified there it points to the
 filename to translate (currently the only available source). If 
 C<'string_ref'> is specified it points to a reference to a string, with the
-contents of the source XML.
+contents of the source XML. If C<'dom'> is specified then it points to an XML
+DOM as parsed or constructed by XML::LibXML.
 
 The C<'output'> key specifies the return value. A value of C<'string'> returns 
-the XML as a string, and a value of C<'xml'> returns the XML as an 
+the XML as a string, and a value of C<'dom'> returns the XML as an 
 L<XML::LibXML> DOM object.
 
 =cut
     my $source = $args->{source};
 
     return
-        exists($source->{'string_ref'})
-            ? $self->_xml_parser()->parse_string(${$source->{'string_ref'}}) 
-            : $self->_xml_parser()->parse_file($source->{'file'})
+          exists($source->{'dom'})
+        ? $source->{'dom'}
+        : exists($source->{'string_ref'})
+        ? $self->_xml_parser()->parse_string(${$source->{'string_ref'}}) 
+        : $self->_xml_parser()->parse_file($source->{'file'})
         ;
 }
 
     {
         return $stylesheet->output_string($results);
     }
-    elsif ($medium eq "xml")
+    elsif ($medium eq "dom")
     {
         return $results;
     }

perl/modules/XML-Grammar-Fiction/t/to-xhtml.t

 use strict;
 use warnings;
 
-use Test::More tests => 32;
+use Test::More tests => 34;
 
 use File::Spec;
 
         if ($format_id eq "xhtml")
         {
             my $file_contents = load_xml($xml_fn);
-            my $from_string_text =
-                $format_hash->{'obj'}->$m(
-                {
-                    source => { string_ref => \$file_contents, },
-                    output => "string",
-                }
-            );
+            {
+                my $from_string_text =
+                    $format_hash->{'obj'}->$m(
+                    {
+                        source => { string_ref => \$file_contents, },
+                        output => "string",
+                    }
+                );
 
-            # TEST*$num_texts
-            is ($from_string_text, $text, "From-string-ref text is OK.")
+                # TEST*$num_texts
+                is ($from_string_text, $text, "From-string-ref text is OK.")
+            }
+
+            {
+                my $parser = XML::LibXML->new();
+                my $file_dom = $parser->parse_string($file_contents);
+
+                my $from_string_text =
+                    $format_hash->{'obj'}->$m(
+                    {
+                        source => { dom => $file_dom, },
+                        output => "string",
+                    }
+                );
+
+                # TEST*$num_texts
+                is ($from_string_text, $text, "From-dom text is OK.")
+            }
         }
         my $parser = XML::LibXML->new();