line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::GlobalEvents; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A module to handle events |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
95559
|
use strict; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
982
|
use File::Find::Rule; |
|
2
|
|
|
|
|
16116
|
|
|
2
|
|
|
|
|
16
|
|
9
|
2
|
|
|
2
|
|
114
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
10
|
2
|
|
|
2
|
|
10
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
173
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
13
|
use base 'Exporter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1043
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(on publish); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.04; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %subscriber; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
1
|
|
|
1
|
1
|
89
|
my ($class, $namespace) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
my @spaces = split /::/, $namespace; |
23
|
1
|
|
|
|
|
5
|
my @dirs = map{ File::Spec->catdir( $_, @spaces ) }@INC; |
|
10
|
|
|
|
|
56
|
|
24
|
1
|
|
|
|
|
31
|
my @files = File::Find::Rule->file->name( '*.pm' )->in( @dirs ); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
2261
|
for my $file ( @files ) { |
27
|
1
|
|
|
|
|
465
|
require $file; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub on { |
32
|
10
|
|
|
10
|
1
|
5117
|
my $object = shift; |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
25
|
my ($event,$sub) = @_; |
35
|
|
|
|
|
|
|
|
36
|
10
|
100
|
|
|
|
40
|
if ( !blessed $object ) { |
37
|
8
|
|
|
|
|
15
|
$sub = $event; |
38
|
8
|
|
|
|
|
10
|
$event = $object; |
39
|
8
|
|
|
|
|
17
|
$object = ''; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
10
|
100
|
100
|
|
|
65
|
return if ref $event or !ref $sub or ref $sub ne 'CODE'; |
|
|
|
100
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
16
|
my $package = "$object"; |
45
|
5
|
100
|
|
|
|
26
|
$package = caller if !$package; |
46
|
5
|
|
|
|
|
17
|
$subscriber{$event}->{$package} = $sub; |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
12
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub publish { |
52
|
7
|
|
|
7
|
1
|
4434
|
my ($event, @param) = @_; |
53
|
|
|
|
|
|
|
|
54
|
7
|
100
|
|
|
|
12
|
for my $package ( sort keys %{ $subscriber{$event} || {} } ) { |
|
7
|
|
|
|
|
48
|
|
55
|
9
|
|
|
|
|
76
|
$subscriber{$event}->{$package}->(@param); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
7
|
|
|
|
|
89
|
return 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |