blib/lib/IO/Async/XMLStream/SAXReader/DuckHandler.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 67 CC 6 SCAR 17.2
CC
6
Cov
0%
AUTOLOAD
12.0
new
6.0
_dyn_method
6.0
CRAP 5.6
1 use 5.008; # utf8
2 use strict;
3 use warnings;
4 use utf8;
5  
6 package IO::Async::XMLStream::SAXReader::DuckHandler;
7 $IO::Async::XMLStream::SAXReader::DuckHandler::VERSION = '0.001000';
8 # ABSTRACT: Deferred Handler proxy for IO::Async constructor-driven interface
9  
10 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11  
12 use Scalar::Util qw(weaken);
13 use Carp qw(croak);
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24 sub new {
25 my ( $self, $opts ) = @_;
26 croak('SAXReader option is mandatory') unless exists $opts->{SAXReader};
27 weaken $opts->{SAXReader};
28 return bless $opts, $self;
29 }
30  
31 sub _dyn_method {
32 my ( $self, $method ) = @_;
33 my $sax = $self->{SAXReader};
34 my $event = 'on_' . $method;
35 my $callback = $sax->can_event($event);
36 return unless $callback;
37 return sub {
38 my ( undef, @args ) = @_;
39 return $callback->( $sax, @args );
40 };
41 }
42  
43 sub can {
44 my ( $self, $method ) = @_;
45 my $orig = $self->SUPER::can($method);
46 return $orig if $orig;
47 return $self->_dyn_method($method);
48 }
49  
50 ## no critic (ClassHierarchies::ProhibitAutoloading)
51 sub AUTOLOAD {
52 my ( $self, @args ) = @_;
53 ( my $methname = our $AUTOLOAD ) =~ s/.+:://msx;
54 return if 'DESTROY' eq $methname;
55 return unless my $meth = $self->_dyn_method($methname);
56 return $meth->( $self, @args );
57 }
58  
59 1;
60  
61 __END__