[Koha-patches] [SIGNED OFF 2/2] Bug 5611 Tidy up C4::Scrubber
Colin Campbell
colin.campbell at ptfs-europe.com
Wed Jan 12 17:53:22 CET 2011
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
---
C4/Scrubber.pm | 52 +++++++++++++++++++++++-----------------------------
t/Scrubber.t | 5 ++++-
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/C4/Scrubber.pm b/C4/Scrubber.pm
index d01795a..854812e 100644
--- a/C4/Scrubber.pm
+++ b/C4/Scrubber.pm
@@ -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;
}
diff --git a/t/Scrubber.t b/t/Scrubber.t
index e0a2ad7..ce1503f 100755
--- a/t/Scrubber.t
+++ b/t/Scrubber.t
@@ -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])"
--
1.7.3.4
More information about the Koha-patches
mailing list