Debian Codegraph @

samples/simple_example

raw
1 #!/opt/perl/bin/perl
2 package test;
3
4 use Object::Event;
5
6 our @ISA = qw/Object::Event/;
7
8 sub new {
9 my $c = shift;
10 my $self = $c->SUPER::new (@_);
11
12 # register on the 'up' event and then call the 'down' event
13 $self->reg_cb (up => sub { $self->event ('down'); });
14
15 $self
16 }
17
18 sub up {
19 my ($self) = @_;
20
21 $self->event ('up'); # genereate an internal up event
22 }
23
24 package main;
25
26 my $t = test->new;
27
28 $t->reg_cb ( # reg_cb registers on a set of specific events
29 down => sub {
30 my ($t) = @_;
31 print "Yay, we got down again...\n";
32 }
33 );
34
35 $t->up; # test will emit the 'down' even we registered upon above