1package Finance::Bitcoin::Role::HasAPI;
2
3BEGIN {
4	$Finance::Bitcoin::Role::HasAPI::AUTHORITY = 'cpan:TOBYINK';
5	$Finance::Bitcoin::Role::HasAPI::VERSION   = '0.902';
6}
7
8use Moo::Role;
9use Finance::Bitcoin::API;
10use Scalar::Util qw( blessed );
11
12has api => (
13	is      => 'rw',
14	default => sub { "Finance::Bitcoin::API"->new },
15);
16
17around 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
351;
36
37__END__
38
39=head1 NAME
40
41Finance::Bitcoin::Role::HasAPI - role for objects with an "api" attribute
42
43=head1 DESCRIPTION
44
45=over
46
47=item C<< api >>
48
49Returns an instance of L<Finance::Bitcoin::API>.
50
51=back
52
53=head1 AUTHOR
54
55Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
56
57=head1 COPYRIGHT
58
59Copyright 2010, 2011, 2013, 2014 Toby Inkster
60
61This library is free software; you can redistribute it and/or modify it
62under the same terms as Perl itself.
63
64=head1 DISCLAIMER OF WARRANTIES
65
66THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
67WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
68MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
69