Bug 5611 Tidy up C4::Scrubber
authorColin Campbell <colin.campbell@ptfs-europe.com>
Wed, 12 Jan 2011 16:53:22 +0000 (16:53 +0000)
committerChris Cormack <chrisc@catalyst.net.nz>
Wed, 12 Jan 2011 17:44:46 +0000 (06:44 +1300)
Remove the unneeded package variables
Remove unnecessary variables
Removed some cargo-cult programming
Tidied the indentation from mix of tabs & spaces
Add a Test that we actually return the required class
of object

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Scrubber.pm
t/Scrubber.t

index d01795a..854812e 100644 (file)
@@ -22,42 +22,36 @@ use HTML::Scrubber;
 use C4::Context;
 use C4::Debug;
 
-use vars qw($VERSION @ISA);
-use vars qw(%scrubbertypes $scrubbertype);
-
-BEGIN {
-       $VERSION = 0.02;
-       # @ISA = qw(HTML::Scrubber);
-}
+our $VERSION = 0.02;
 
 
 my %scrubbertypes = (
-       default => {},  # place holder, default settings are below as fallbacks in call to constructor
-           tag => {},  # uses defaults
-       comment => {
-       allow   => [qw( br b i em big small strong )],
-       },
-       staff   => {
-       default => [ 1 =>{'*'=>1} ],
-       comment => 1,
-       },
+    default => {}, # place holder, default settings are below as fallbacks in call to constructor
+    tag     => {},                                               # uses defaults
+    comment => { allow => [qw( br b i em big small strong )], },
+    staff   => {
+        default => [ 1 => { '*' => 1 } ],
+        comment => 1,
+    },
 );
 
 
 sub new {
-       my $fakeself = shift;   # not really OO, we return an HTML::Scrubber object.
-       my $type  = (@_) ? shift : 'default';
-       exists $scrubbertypes{$type} or croak "New called with unrecognized type '$type'";
-       $debug and print STDERR "Building new Scrubber of type '$type'\n";
-       my $settings = $scrubbertypes{$type};
-       my $scrubber = HTML::Scrubber->new(
-               allow   => exists $settings->{allow}   ? $settings->{allow}   : [],
-               rules   => exists $settings->{rules}   ? $settings->{rules}   : [],
-               default => exists $settings->{default} ? $settings->{default} : [ 0 =>{'*'=>0} ],
-               comment => exists $settings->{comment} ? $settings->{comment} : 0,
-               process => 0,
-       );
-       return $scrubber;
+    shift; # ignore our class we are wraooer
+    my $type = (@_) ? shift : 'default';
+    if ( !exists $scrubbertypes{$type} ) {
+        croak "New called with unrecognized type '$type'";
+    }
+    $debug and carp "Building new Scrubber of type '$type'";
+    my $settings = $scrubbertypes{$type};
+    my $scrubber = HTML::Scrubber->new(
+        allow   => exists $settings->{allow} ? $settings->{allow} : [],
+        rules   => exists $settings->{rules} ? $settings->{rules} : [],
+        default => exists $settings->{default} ? $settings->{default} : [ 0 => { '*' => 0 } ],
+        comment => exists $settings->{comment} ? $settings->{comment} : 0,
+        process => 0,
+    );
+    return $scrubber;
 }
 
 
index e0a2ad7..ce1503f 100755 (executable)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 11;
 BEGIN {
        use FindBin;
        use lib $FindBin::Bin;
@@ -46,6 +46,9 @@ At the end here, I actually have some regular text.
 print pretty_line("Original HTML:"), $html, "\n", pretty_line();
 $collapse and diag "Note: scrubber test output will have whitespace collapsed for readability\n";
 ok($scrubber = C4::Scrubber->new(), "Constructor: C4::Scrubber->new()");
+
+isa_ok($scrubber, 'HTML::Scrubber', 'Constructor returns HTML::Scrubber object');
+
 ok(printf("# scrubber settings: default %s, comment %s, process %s\n",
        $scrubber->default(),$scrubber->comment(),$scrubber->process()),
        "Outputting settings from scrubber object (type: [default])"