Permalink
Browse files

Added more debugging options, added the evil failing test of a changi…

…ng query....
  • Loading branch information...
1 parent d22d0cf commit 29741c94cdfb1dd2d62203ffb35139f809983eb0 @Getty Getty committed Mar 10, 2013
Showing with 44 additions and 4 deletions.
  1. +8 −2 lib/DDG/Block.pm
  2. +13 −2 t/35-block.t
  3. +23 −0 t/lib/DDGTest/Goodie/Changequery.pm
View
@@ -141,9 +141,11 @@ has debug_trace => (
sub trace {
my $self = shift;
return unless $self->debug_trace;
- print STDERR ("[".(ref $self)."] ",join(" ",map { defined $_ ? $_ : 'undef' } @_),"\n");
+ print STDERR ("[".$self->trace_name."] ",join(" ",map { defined $_ ? $_ : 'undef' } @_),"\n");
}
+sub trace_name { ref(shift) }
+
=attr before_build
A coderef that is executed before the build of the plugins. It gets the block
@@ -319,9 +321,13 @@ sub handle_request_matches {
return @results;
}
-before request => sub {
+around request => sub {
+ my $orig = shift;
my ( $self, $request ) = @_;
$self->trace( "Query raw:", "'".$request->query_raw."'" );
+ my @results = $orig->(@_);
+ $self->trace( "Query", "'".$request->query_raw."'", "produced", scalar @results, "results" );
+ return @results;
};
1;
View
@@ -200,8 +200,6 @@ BEGIN {
return_one => 1,
});
- isa_ok($one_words_block,'DDG::Block::Words');
-
my @one_queries = (
'aROUNd two' => {
wo => [zci('two','woblockone')],
@@ -229,6 +227,19 @@ BEGIN {
my @words_result = $one_words_block->request($request);
is_deeply(\@words_result,$expect->{wo} ? $expect->{wo} : [],'Testing words block result of query "'.$query.'"');
}
+
+ # evil test for a plugin that somehow manages to change the query
+ # on the processing...
+ {
+ my $query_change = DDG::Block::Words->new({
+ plugins => [qw( DDGTest::Goodie::Changequery )],
+ return_one => 1,
+ });
+ my $request = DDG::Request->new({ query_raw => 'duckduckgo ios' });
+ is($request->query_raw,'duckduckgo ios','Query is fine before query_change block');
+ my @words_result = $query_change->request($request);
+ is($request->query_raw,'duckduckgo ios','Query is still fine after query_change block');
+ }
}
@@ -0,0 +1,23 @@
+package DDGTest::Goodie::Changequery;
+
+#
+# Evil case of a plugin that somehow modifies the query on working with it
+#
+
+use DDG::Goodie;
+
+triggers startend => 'duckduckgo','ios';
+
+# list of trigger words
+my $words = 'ios';
+
+handle query_raw => sub {
+ if (m/$words/i){
+ my $query = $_;
+ s/$words//ig;
+ return $query if length $_ > 1;
+ }
+ return;
+};
+
+1;

0 comments on commit 29741c9

Please sign in to comment.