summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-03-01 17:37:04 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-03-01 17:37:04 +0100
commite4995e57f3bd978f10585890c671c613f6531c2e (patch)
treeb7b25d8bb913a4dffbadc5896ecb952a3b652981
parent47f72633b8f571170718e2123c0e9066b4063d84 (diff)
App::Dthumb::Data: Exactly preserve text files, add test for it
-rw-r--r--lib/App/Dthumb/Data.pm.PL10
-rwxr-xr-xt/29-app-dthumb-data.t28
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL
index a686c6d..ba99c82 100644
--- a/lib/App/Dthumb/Data.pm.PL
+++ b/lib/App/Dthumb/Data.pm.PL
@@ -67,19 +67,23 @@ sub get {
die("No such data: ${name}\n");
}
+ $data = ${$data};
+
+ chomp($data);
+
if ($name =~ qr{ \. (png | gif) $ }ox) {
- return decode_base64(${$data});
+ return decode_base64($data);
}
while (my ($key, $value) = each %{$self->{replace}}) {
- ${$data} =~ s{
+ $data =~ s{
( \<\!-- | /\* )
\s+ \$ $key \s+
( --\> | \*/ )
}{$value}gx;
}
- return ${$data};
+ return $data;
}
1;
diff --git a/t/29-app-dthumb-data.t b/t/29-app-dthumb-data.t
new file mode 100755
index 0000000..42e9b41
--- /dev/null
+++ b/t/29-app-dthumb-data.t
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+use autodie;
+
+use App::Dthumb::Data;
+use Test::More;
+
+opendir(my $share, 'share');
+my @files = grep { /^[^.]/ } readdir($share);
+closedir($share);
+
+plan(
+ tests => 1 + scalar @files,
+);
+
+my $dthumb = App::Dthumb::Data->new();
+
+isa_ok($dthumb, 'App::Dthumb::Data', 'App::Dthumb::Data->new()');
+
+for my $file (@files) {
+ open(my $fh, '<', "share/${file}");
+ my $data = do { local $/ = undef; <$fh> };
+ close($fh);
+
+ is($dthumb->get($file), $data, "\$dthumb->get($file)");
+}