Apache2-Autocomplete

 view release on metacpan or  search on metacpan

lib/Apache2/Autocomplete.pm  view on Meta::CPAN

This is the main method which calls the I<expand> method
to find and format the results to be returned for the
autocompletion.

By default, the only header Apache::Autocomplete sets is
the I<Content-Type>, for which I<text/html> is used.
If additional headers are required, they may
be passed as an optional argument into I<run()>in the
form of a hash reference, as in

  my $header = {'Content-Type' => 'text/html; charset=utf-8',
		'X-err_header_out' => 'err_headers_out',
	       };
  $ac->run($header);

=item * my $r = $ac-E<gt>r;

This returns the L<Apache2::RequestRec> object passed into
the I<new> method.

=item * my $cgi = $ac-E<gt>cgi;

t/autocomplete/names_header.t  view on Meta::CPAN

use Apache::TestRequest;

my $module = 'TestAutocomplete::names_header';
my $path = Apache::TestRequest::module2path($module);

plan tests => 11;

my $res = GET "/$path";
ok t_cmp($res->code, 200, "Checking request was OK");
ok t_cmp $res->header('Content-Type'),
    'text/html; charset=utf-8',
    'Content-Type: made it';
ok t_cmp $res->header('X-err_header_out'),
    'err_headers_out',
    'X-err_header_out: made it';
my $content = $res->content;
ok t_cmp($content, qr{parent.sendRPCDone}, 
	"Checking presence of parent.sendRPCDone");

$res = GET "/$path?qu=ja;js=true";
ok t_cmp($res->code, 200, "Checking request was OK");
ok t_cmp $res->header('Content-Type'),
    'text/html; charset=utf-8',
    'Content-Type: made it';
ok t_cmp $res->header('X-err_header_out'),
    'err_headers_out',
    'X-err_header_out: made it';
$content = $res->content;
ok t_cmp($content, qr{sendRPCDone}, 
	"Checking presence of sendRPCDone");
ok t_cmp($content, qr{jane}, 
	"Checking that janice arrived");
ok t_cmp($content, qr{janice}, 

t/response/TestAutocomplete/names_header.pm  view on Meta::CPAN

sub expand {
  my ($self, $query) = @_;
  my $re = qr/^\Q$query\E/i;
  my @names = grep /$re/, @NAMES;
  my @desc = map {"42 is the answer"} @names;
  (lc $query, \@names, \@desc, [""]);
}

sub handler {
  my $r = shift;
  my $header = {'Content-Type' => 'text/html; charset=utf-8',
		'X-err_header_out' => 'err_headers_out',
	       };
  my $ac = __PACKAGE__->new($r);
  $ac->run($header);
  return Apache2::Const::OK;
}

1;

__END__



( run in 0.252 second using v1.01-cache-2.11-cpan-4d50c553e7e )