File Coverage

blib/lib/POE/Component/Server/Bayeux/Utilities.pm
Criterion Covered Total %
statement 19 20 95.0
branch 11 12 91.6
condition 3 3 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 37 40 92.5


line stmt bran cond sub pod time code
1             package POE::Component::Server::Bayeux::Utilities;
2              
3 4     4   28799 use strict;
  4         9  
  4         149  
4 4     4   24 use warnings;
  4         8  
  4         124  
5              
6 4     4   22 use base qw(Exporter);
  4         10  
  4         1397  
7             our %EXPORT_TAGS = ( all => [qw(channel_match)] );
8             our @EXPORT_OK = qw(channel_match);
9              
10             sub channel_match {
11 10     10 0 5435 my ($from, $to) = @_;
12              
13             # Should channel $from be delivered to someone subscribed to channel $to?
14              
15 10 100       30 return 1 if $from eq $to;
16              
17 9         32 my @from = split /\//, $from;
18 9         28 my @to = split /\//, $to;
19              
20 9         30 for (my $i = 0; $i <= $#from; $i++) {
21 23 100       53 return 0 if ! defined $to[$i];
22              
23             # Match all
24 22 100       51 return 1 if $to[$i] eq '**';
25              
26             # If simple glob '*' and from has no more parts
27 21 100 100     71 return 1 if $to[$i] eq '*' && $#from == $i;
28              
29 19 100       73 return 0 if $from[$i] ne $to[$i];
30             }
31              
32 1 50       7 return 0 if int @to > int @from;
33              
34             # If here, it matched
35 0           return 1;
36             }
37              
38             1;