line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Rx::Subject; |
2
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
67
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use base 'Mojo::Rx::Observable'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
151
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
24
|
use Mojo::Rx::Utils 'get_subscription_from_subscriber'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
728
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "v0.13.0"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
0
|
|
my ($class) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my %subscribers; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $self; $self = $class->SUPER::new(sub { |
17
|
0
|
|
|
0
|
|
|
my ($subscriber) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if ($self->{_closed}) { |
20
|
0
|
0
|
|
|
|
|
$subscriber->{complete}->() if defined $subscriber->{complete}; |
21
|
0
|
|
|
|
|
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$subscribers{$subscriber} = $subscriber; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return sub { |
27
|
0
|
|
|
|
|
|
delete $subscribers{$subscriber}; |
28
|
0
|
|
|
|
|
|
}; |
29
|
0
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self->{_closed} = 0; |
32
|
0
|
|
|
|
|
|
foreach my $type (qw/ error complete /) { |
33
|
|
|
|
|
|
|
$self->{$type} = sub { |
34
|
0
|
|
|
0
|
|
|
$self->{_closed} = 1; |
35
|
0
|
|
|
|
|
|
foreach my $subscriber (values %subscribers) { |
36
|
0
|
0
|
|
|
|
|
$subscriber->{$type}->(@_) if defined $subscriber->{$type}; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
%subscribers = (); |
39
|
|
|
|
|
|
|
# TODO: maybe: delete @$self{qw/ next error complete /}; |
40
|
|
|
|
|
|
|
# (Think about how subclasses such as BehaviorSubjects will be affected) |
41
|
0
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
$self->{next} = sub { |
44
|
0
|
|
|
0
|
|
|
foreach my $subscriber (values %subscribers) { |
45
|
0
|
0
|
|
|
|
|
$subscriber->{next}->(@_) if defined $subscriber->{next}; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |