File: 04-subclassing.t

package info (click to toggle)
libhttp-exception-perl 0.04007-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 300 kB
  • sloc: perl: 232; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,120 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
use strict;

use Test::Exception;
use Test::More;
use HTTP::Exception;

{
    package My::HTTP::Exception;
    use base 'HTTP::Exception::200';

    sub code    { 999 }
    sub my_info { 'Interesting Info' }
    sub status_message { 'Interesting Message' }
}

throws_ok sub { My::HTTP::Exception->throw; },
    'My::HTTP::Exception' ;

ok defined My::HTTP::Exception->caught,
    'custom HTTP::Exception caught';

ok defined HTTP::Exception::200->caught,
    'custom HTTP::Exception caught with HTTP::Exception::200';

ok defined HTTP::Exception::OK->caught,
    'custom HTTP::Exception caught with HTTP::Exception::OK';

ok !defined HTTP::Exception::404->caught,
    'custom HTTP::Exception not caught with wrong HTTP::Exception::OK';

my $e = HTTP::Exception->caught;
ok defined $e,          'custom HTTP::Exception caught with HTTP::Exception';
is $e->code,            999, 'code overridden';
is $e->my_info,         'Interesting Info', 'additional sub exists';
is $e->status_message,  'Interesting Message', 'Status Message changed';
is $e->as_string,       'Interesting Message', 'as_string changed';

done_testing;