| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IPC::PubSub::Subscriber; | 
| 2 | 2 |  |  | 2 |  | 9 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 64 |  | 
| 3 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 52 |  | 
| 4 | 2 |  |  | 2 |  | 8 | use base qw/Class::Accessor::Fast/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 952 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(qw/_pubs _cache/); | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 4 |  |  | 4 | 1 | 52 | my $class = shift; | 
| 10 | 4 |  |  |  |  | 7 | my $cache = shift; | 
| 11 | 4 |  |  |  |  | 9 | my $pubs = { map { $_ => $cache->publisher_indices($_); } @_ }; | 
|  | 4 |  |  |  |  | 24 |  | 
| 12 | 4 |  |  |  |  | 5043 | bless({ _cache => $cache, _pubs => $pubs }); | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub channels { | 
| 16 | 12 |  |  | 12 | 0 | 19 | my $self = shift; | 
| 17 |  |  |  |  |  |  | wantarray | 
| 18 | 12 | 50 |  |  |  | 27 | ? keys(%{$self->_pubs}) | 
|  | 12 |  |  |  |  | 182 |  | 
| 19 |  |  |  |  |  |  | : $self->_pubs; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub subscribe { | 
| 23 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 24 | 0 |  | 0 |  |  | 0 | $self->_pubs->{$_} ||= $self->_cache->publisher_indices($_) for @_; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub unsubscribe { | 
| 28 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 29 | 0 |  |  |  |  | 0 | delete @{$self->_pubs}{@_}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub get_all { | 
| 33 | 6 |  |  | 6 | 0 | 2983 | my $self = shift; | 
| 34 | 6 |  |  |  |  | 23 | my $pubs = $self->_pubs; | 
| 35 | 6 |  |  |  |  | 45 | my $cache = $self->_cache; | 
| 36 |  |  |  |  |  |  | return { | 
| 37 | 6 |  |  |  |  | 41 | map { | 
| 38 | 6 |  |  |  |  | 37 | my $orig = $pubs->{$_}; | 
| 39 | 6 |  |  |  |  | 26 | $pubs->{$_} = $cache->publisher_indices($_); | 
| 40 | 6 |  |  |  |  | 32392 | $_ => [ grep { defined } $cache->get($_, $orig, $pubs->{$_})]; | 
|  | 4 |  |  |  |  | 24 |  | 
| 41 |  |  |  |  |  |  | } $self->channels | 
| 42 |  |  |  |  |  |  | }; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub get { | 
| 46 | 6 |  |  | 6 | 1 | 6261 | my $self    = shift; | 
| 47 | 6 |  |  |  |  | 27 | my $pubs    = $self->_pubs; | 
| 48 | 6 |  |  |  |  | 39 | my $cache   = $self->_cache; | 
| 49 | 6 | 50 |  |  |  | 44 | my ($chan)  = @_ ? @_ : sort($self->channels) or return; | 
|  |  | 50 |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 6 |  |  |  |  | 51 | my $orig = $pubs->{$chan}; | 
| 52 | 6 |  |  |  |  | 31 | $pubs->{$chan} = $cache->publisher_indices($chan); | 
| 53 |  |  |  |  |  |  | wantarray | 
| 54 | 0 | 0 |  |  |  | 0 | ? map {$_ ? $_->[1] : ()} $cache->get($chan, $orig, $pubs->{$chan}) | 
|  | 6 | 50 |  |  |  | 73 |  | 
| 55 | 6 | 100 |  |  |  | 13799 | : [map {$_ ? $_->[1] : ()} $cache->get($chan, $orig, $pubs->{$chan})]; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | 1; |