labia

Saturday 30 August 2003 - Monday 1 September 2003

Finished modularising OpenGuides::SuperSearch - well, as much of it as I can do without feedback from Ivor. The code could still do with a bit more refactoring, since it's all over the place, but my goal was to make it testable, and I've done that.

This is how you use it (yes, this is the entire CGI script):

  use CGI;
  use Config::Tiny;
  use OpenGuides::SuperSearch;

  my $config = Config::Tiny->read( "wiki.conf" );
  my $search = OpenGuides::SuperSearch->new( config => $config );
  my %vars = CGI::Vars();
  $search->run( vars => \%vars );

This is how you test the data retrieval:

  my %tt_vars = $search->run(
                              return_tt_vars => 1,
                              vars           => { search => "banana" },
                            );
  is( $tt_vars{first_num}, 0, "first_num set to 0 when no hits" );
  is( scalar @{ $tt_vars{results} }, 0, "...and results array empty" );

This is how you test the output produced by the module and the associated template:

  my $output = $search->run(
                             return_output => 1,
                             vars          => { search => "banana" },
                           );
  like( $output, qr/no items matched/i,
        "outputs 'no items matched' if term not found"

I like this method; it feels clean. Better than what I did with CGI::Wiki::Kwiki, which was to capture the output by tying STDOUT to an IO::Scalar.

< Tuesday 2 September 2003 Friday 29 August 2003 >

foo

HTML generated from pod with podblog