File: 003_basic_with_options.t

package info (click to toggle)
libfcgi-engine-perl 0.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 3,226; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 16;
use Test::Moose;

BEGIN {
    use_ok('FCGI::Engine');
}

{
    package Foo;
    sub dispatcher {
        if (@_ == 3 && $_[0] eq 'Foo' && $_[1] eq 'q') {
            ::pass("... dispatcher was called");
        }
        else {
            ::fail("... dispatcher was called with wrong args");
        }
    }
}

@ARGV = ();

my $e = FCGI::Engine->new_with_options(
    handler_class        => 'Foo',
    handler_method       => 'dispatcher',
    handler_args_builder => sub { (q => CGI::Simple->new) },
    nproc                => 10,
);
isa_ok($e, 'FCGI::Engine');
does_ok($e, 'MooseX::Getopt');

ok(!$e->is_listening, '... we are not listening');
is($e->nproc, 10, '... we have the default 1 proc (but we are not using it)');
ok(!$e->has_pidfile, '... we have no pidfile');
ok(!$e->should_detach, '... we shouldnt daemonize');
is($e->manager, 'FCGI::Engine::ProcManager', '... we have the default manager (FCGI::Engine::ProcManager)');

ok(!$e->has_pre_fork_init, '... we dont have any pre-fork-init');

is($e->handler_class, 'Foo', '... we have a handler class');
is($e->handler_method, 'dispatcher', '... we have our default handler method');

my $handler_args_builder = $e->handler_args_builder;
is(ref $handler_args_builder, 'CODE', '... default handler args is an CODE ref');

my $handler_args = [ $handler_args_builder->() ]; 
is($handler_args->[0], 'q', '... got our right default arg');
isa_ok($handler_args->[1], 'CGI::Simple', '... default arg isa CGI::Simple');


eval { $e->run }; 
ok(!$@, '... we ran the handler okay');