File Coverage

blib/lib/Finance/Bitcoin/Role/HasAPI.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Finance::Bitcoin::Role::HasAPI;
2              
3             BEGIN {
4 1     1   14221 $Finance::Bitcoin::Role::HasAPI::AUTHORITY = 'cpan:TOBYINK';
5 1         29 $Finance::Bitcoin::Role::HasAPI::VERSION = '0.902';
6             }
7              
8 1     1   9 use Moo::Role;
  1         3  
  1         8  
9 1     1   409 use Finance::Bitcoin::API;
  1         2  
  1         35  
10 1     1   5 use Scalar::Util qw( blessed );
  1         2  
  1         438  
11              
12             has api => (
13             is => 'rw',
14             default => sub { "Finance::Bitcoin::API"->new },
15             );
16              
17             around BUILDARGS => sub
18             {
19             my $orig = shift;
20             my $class = shift;
21            
22             if (scalar @_ == 1 and blessed $_[0])
23             {
24             return $class->$orig(api => @_);
25             }
26             elsif (scalar @_ == 1 and $_[0] =~ /^http/)
27             {
28             my $api = "Finance::Bitcoin::API"->new(endpoint => "$_[0]");
29             return $class->$orig(api => $api);
30             }
31            
32             return $class->$orig(@_);
33             };
34              
35             1;
36              
37             __END__
38              
39             =head1 NAME
40              
41             Finance::Bitcoin::Role::HasAPI - role for objects with an "api" attribute
42              
43             =head1 DESCRIPTION
44              
45             =over
46              
47             =item C<< api >>
48              
49             Returns an instance of L<Finance::Bitcoin::API>.
50              
51             =back
52              
53             =head1 AUTHOR
54              
55             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
56              
57             =head1 COPYRIGHT
58              
59             Copyright 2010, 2011, 2013, 2014 Toby Inkster
60              
61             This library is free software; you can redistribute it and/or modify it
62             under the same terms as Perl itself.
63              
64             =head1 DISCLAIMER OF WARRANTIES
65              
66             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
67             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
68             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.