File Coverage

blib/lib/AnyEvent/Retry/Types.pm
Criterion Covered Total %
statement 19 20 95.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 27 30 90.0


line stmt bran cond sub pod time code
1             package AnyEvent::Retry::Types;
2             BEGIN {
3 4     4   104 $AnyEvent::Retry::Types::VERSION = '0.03';
4             }
5             # ABSTRACT: Types used internally by C<AnyEvent::Retry>
6 4     4   26 use strict;
  4         8  
  4         196  
7 4     4   23 use warnings;
  4         9  
  4         126  
8 4     4   3880 use true;
  4         41660  
  4         34  
9              
10 4     4   6708 use MooseX::Types -declare => ['Interval'];
  4         59489  
  4         51  
11 4     4   21544 use MooseX::Types::Moose qw(Str HashRef);
  4         16080  
  4         44  
12              
13             role_type Interval, { role => 'AnyEvent::Retry::Interval::API' };
14              
15             sub class_name {
16 6     6 0 11 my $str = shift;
17 6 50       22 if(/^\+(.+)$/){
18 0         0 return $1;
19             }
20             else {
21 6         21 return "AnyEvent::Retry::Interval::$str";
22             }
23             }
24              
25             coerce Interval, from Str, via {
26             my $name = class_name($_);
27             Class::MOP::load_class($name);
28             return $name->new;
29             };
30              
31             coerce Interval, from HashRef, via {
32             my $req = [keys %$_]->[0];
33             my $args = $_->{$req};
34              
35             my $name = class_name($req);
36             Class::MOP::load_class($name);
37             return $name->new($args);
38             };
39              
40             __END__
41             =pod
42              
43             =head1 NAME
44              
45             AnyEvent::Retry::Types - Types used internally by C<AnyEvent::Retry>
46              
47             =head1 VERSION
48              
49             version 0.03
50              
51             =head1 AUTHOR
52              
53             Jonathan Rockway <jrockway@cpan.org>
54              
55             =head1 COPYRIGHT AND LICENSE
56              
57             This software is copyright (c) 2010 by Jonathan Rockway.
58              
59             This is free software; you can redistribute it and/or modify it under
60             the same terms as the Perl 5 programming language system itself.
61              
62             =cut
63