File Coverage

blib/lib/Plient/Protocol.pm
Criterion Covered Total %
statement 14 27 51.8
branch 1 10 10.0
condition 2 5 40.0
subroutine 4 6 66.6
pod 0 3 0.0
total 21 51 41.1


line stmt bran cond sub pod time code
1             package Plient::Protocol;
2              
3 2     2   740 use warnings;
  2         5  
  2         58  
4 2     2   10 use strict;
  2         3  
  2         51  
5 2     2   9 use Carp;
  2         5  
  2         728  
6              
7 0     0 0 0 sub prefix { warn "needs subclass prefix"; '' }
  0         0  
8 0     0 0 0 sub methods { warn "needs subclass methods"; '' }
  0         0  
9              
10             sub support_method {
11             # trans $args here to let handlers to decide to pass or not
12 1     1 0 3 my ( $class, $method_name, $args ) = @_;
13 1         2 $method_name = lc $method_name;
14 1   50     3 $args ||= {};
15              
16 1 0 33     4 if ( ! $args->{check_only} && !grep { $method_name eq $_ } $class->methods ) {
  0         0  
17 0         0 warn "$method_name for $class is not officially supported yet";
18             }
19              
20 1 50       20 return $class->can($method_name) if $class->can($method_name);
21 0           my $handler_method_name = $class->prefix . "_$method_name";
22 0           for my $handler ( Plient->handlers( $class->prefix ) ) {
23 0 0         $handler->init if $handler->can('init');
24 0 0         if ( my $method =
25             $handler->support_method( $handler_method_name, $args ) )
26             {
27 0           return $method;
28             }
29             }
30 0 0         warn "$handler_method_name is not supported in available handlers"
31             unless $args->{check_only};
32 0           return;
33             }
34              
35             1;
36              
37             __END__