Client.pm

filter: Statementstmt 82.5% 33 / 40 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 77.9% 46 / 59 CC 5 SCAR 11.5
CC
5
Cov
75%
AUTOLOAD
6.9
contract
2.0
BEGIN
1.0
CRAP 3.2
« Contract/ContractResponse.pm ↑ Summary Contract/Helper/UnitConversion.pm »
1 package Ethereum::RPC::Client;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Ethereum::RPC::Contract;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.03';
12  
13 has host => (
14 is => 'ro',
15 3 ▶ default => sub { '127.0.0.1' });
Subroutine __ANON__: called CC=1 SCAR=0.0
16 5 has port => (
17 is => "ro",
18 default => 8545
19 );
20 has http_client => (
21 is => 'ro',
22 3 ▶ default => sub { Mojo::UserAgent->new });
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 ## no critic (RequireArgUnpacking)
25 sub AUTOLOAD {
26 6 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=5 SCAR=19.3
27  
28 6 my $method = $Ethereum::RPC::Client::AUTOLOAD;
29 6 $method =~ s/.*:://;
30  
31 6 ▶ return if ($method eq 'DESTROY');
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 3 3 6
32  
33 3 my $url = "http://" . $self->host . ":" . $self->port;
34  
35 3 $self->{id} = 1;
36 my $obj = {
37 3 ▶ id => $self->{id}++,
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 3 3
38 method => $method,
39 params => (ref $_[0] ? $_[0] : [@_]),
40 };
41  
42 3 my $res = $self->http_client->post($url => json => $obj)->result;
43  
44 0 ▶ return $res->json->{result} unless $res->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_error 0 0 0
45 0 ▶ return $res->message if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
46 0 return undef;
47  
48 }
49  
50 =head2 contract
51  
52 Creates a new contract instance
53  
54 Parameters:
55 contract_address ( Optional - only if the contract already exists ),
56 contract_abi ( Required - https://solidity.readthedocs.io/en/develop/abi-spec.html ),
57 from ( Optional - Address )
58 gas ( Optional - Integer gas )
59 gas_price ( Optional - Integer gasPrice )
60  
61 Return:
62 New contract instance
63  
64 =cut
65  
66 sub contract {
67 0 ▶ my $self = shift;
Subroutine contract: not called CC=1 SCAR=6.9
Pod documented
68 0 my $params = shift;
69 0 return Ethereum::RPC::Contract->new((%{$params}, rpc_client => $self));
70 }
71  
72 5 1;
73  
74 =pod
75  
76 =head1 NAME
77  
78 Ethereum::RPC::Client - Ethereum JSON-RPC Client
79  
80 =head1 SYNOPSIS
81  
82 use Ethereum::RPC::Client;
83  
84 # Create Ethereum::RPC::Client object
85 my $eth = Ethereum::RPC::Client->new(
86 host => "127.0.0.1",
87 );
88  
89 my $web3_clientVersion = $eth->web3_clientVersion;
90  
91 # https://github.com/ethereum/wiki/wiki/JSON-RPC
92  
93 =head1 DESCRIPTION
94  
95 This module implements in PERL the JSON-RPC of Ethereum L<https://github.com/ethereum/wiki/wiki/JSON-RPC>
96  
97 =head1 SEE ALSO
98  
99 L<Bitcoin::RPC::Client>
100  
101 =head1 AUTHOR
102  
103 Binary.com E<lt>fayland@binary.comE<gt>
104  
105 =head1 COPYRIGHT
106  
107 Copyright 2017- Binary.com
108  
109 =head1 LICENSE
110  
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.
113  
114 =cut
« Contract/ContractResponse.pm ↑ Summary Contract/Helper/UnitConversion.pm »