File: 01_basic.t

package info (click to toggle)
libobject-pluggable-perl 1.29-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 232 kB
  • sloc: perl: 678; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 2,127 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use strict;
use warnings;
use Test::More tests => 7;

{
    package TestSubClass;
    use strict;
    use warnings;
    use base qw(Object::Pluggable);
    use Test::More;
    use Object::Pluggable::Constants qw(:ALL);

    sub spawn {
        my $package = shift;
        my $self = bless { }, $package;
        $self->_pluggable_init(
            types => ['SERVER'],
        );
        return $self;
    }

    sub shutdown {
        my ($self) = @_;
        $self->_pluggable_destroy();
        return;
    }

    sub send_event {
        my ($self, $event, @args) = @_;
        $self->_pluggable_process('SERVER', $event, \@args);
        return;
    }

    sub run {
        my ($self) = @_;
        $self->send_event('test');
        $self->send_event('noret');
        return;
    }

    sub _pluggable_event {
        my ($self, @args) = @_;
        $self->send_event(@args);
        return;
    }

    sub SERVER_test {
        pass(__PACKAGE__ . ' test event');
        return PLUGIN_EAT_NONE;
    }
    sub SERVER_noret {
        pass(__PACKAGE__ . ' noret event');
        return;
    }
}

{
    package TestPlugin;
    use strict;
    use warnings;
    use Test::More;
    use Object::Pluggable::Constants qw(:ALL);

    sub new {
        my $package = shift;
        return bless { @_ }, $package;
    }

    sub plugin_register {
        my ($self,$subclass) = splice @_, 0, 2;
        pass(__PACKAGE__ . " Plugin Register");
        $subclass->plugin_register( $self, 'SERVER', qw(all) );
        return 1;
    }

    sub plugin_unregister {
        pass(__PACKAGE__ . " Plugin Unregister");
        return 1;
    }

    sub SERVER_test {
        my ($self,$irc) = splice @_, 0, 2;
        pass(__PACKAGE__ . ' test event');
        return PLUGIN_EAT_NONE;
    }

    sub SERVER_noret {
        my ($self,$irc) = splice @_, 0, 2;
        pass(__PACKAGE__ . ' noret event');
        return;
    }
}

use strict;
use warnings;

my $pluggable = TestSubClass->spawn();
isa_ok($pluggable, 'Object::Pluggable' );
$pluggable->plugin_add( 'TestPlugin', TestPlugin->new() );
$pluggable->run();
$pluggable->shutdown();