Subject: | Fixes to make tests pass & output to strings work |
Date: | Fri, 08 Aug 2008 01:17:13 +0200 (CEST) |
To: | bug-Pod-Tree [...] rt.cpan.org |
From: | Havard Eidnes <he [...] NetBSD.org> |
Hi,
while packaging an update of Pod::Tree for pkgsrc, I found that
many of the tests in this package fail.
I've dug a bit deeper, and have come up with the attached patches
which fix these problems.
This should also fix the other reported problem, id 34755.
One major problem which caused many of the tests to fail is the
_resolve_dest() in Pod::Tree::HTML, when used with HTML::Stream
version 1.60 (not sure that version matters), and the code ended
up making files named SCALAR(0xaddr) in the top-level directory
instead of writing to the variable given by the scalar reference.
Proper detection and use of IO::String fixes this problem.
This also gets rid of the half-assed and confusing IO::String in
the tests, and instead uses the real IO::String -- the proper use
of IO::String in Pod::Tree::HTML conflicts with the dummy define
in the tests and cropped up as the next problem after the first
one was fixed. This again caused some of the tests having to be
rewritten to fish out the string reference out of the IO::String
object.
Best regards,
- HÃ¥vard
--- lib/Pod/Tree/HTML.pm.orig 2007-06-24 16:51:41.000000000 +0200
+++ lib/Pod/Tree/HTML.pm
@@ -5,6 +5,7 @@
use strict;
use HTML::Stream;
use IO::File;
+use IO::String;
use Pod::Tree;
use Text::Template;
@@ -120,7 +121,12 @@ sub _resolve_dest
isa($dest, 'IO::File' ) and return ($dest, new HTML::Stream $dest);
can($dest, 'print' ) and return ($dest, new HTML::Stream $dest);
- if (ref $dest eq 'SCALAR' or ref $dest eq '' and $dest)
+ if (ref $dest eq 'SCALAR')
+ {
+ my $fh = new IO::String $dest;
+ return ($fh, new HTML::Stream $fh);
+ }
+ if (ref $dest eq '' and $dest)
{
my $fh = new IO::File;
$fh->open($dest, '>') or die "Pod::Tree::HTML::new: Can't open $dest: $!\n";
--- t/html.t.orig 2007-06-24 16:57:52.000000000 +0200
+++ t/html.t
@@ -3,6 +3,7 @@
use strict;
use diagnostics;
use HTML::Stream;
+use IO::String;
use Pod::Tree;
use Pod::Tree::HTML;
@@ -97,7 +98,7 @@ sub Dest1
$html->translate;
my $expected = ReadFile("$Dir/paragraph.exp");
- $$actual eq $expected or Not; OK;
+ ${$actual->string_ref} eq $expected or Not; OK;
}
sub Dest2
@@ -122,7 +123,7 @@ sub Dest3
$html->translate;
my $expected = ReadFile("$Dir/paragraph.exp");
- my $actual = $$string;
+ my $actual = ${$string->string_ref};
$actual eq $expected or Not; OK;
}
@@ -265,19 +266,3 @@ sub WriteFile
close FILE;
chmod 0644, $file or die "Can't chmod $file: $!\n";
}
-
-
-package IO::String;
-
-sub new
-{
- my $self = '';
- bless \$self, shift;
-}
-
-sub print
-{
- my $self = shift;
- $$self .= join('', @_);
-}
-
--- Makefile.PL.orig 2008-08-08 01:02:27.000000000 +0200
+++ Makefile.PL
@@ -16,5 +16,6 @@ WriteMakefile(NAME => 'Pod::Tree',
EXE_FILES => [qw(podtree2html pods2html perl2html)],
PREREQ_PM => { HTML::Stream => 1.49,
Pod::Escapes => 1.02,
+ IO::String => 0,
Text::Template => 1 },
);