| 1 | package WWW::MailboxOrg::JSONRPCRequest; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: JSON-RPC 2.0 request object | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | has jsonrpc => ( | |||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 12 | default => '2.0', | ||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 1 | has method => ( | |||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | has params => ( | ||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 1 | has id => ( | |||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 30 | predicate => 'has_id', | ||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 1 | has url => ( | |||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | has headers => ( | ||||||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ); | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | sub to_hash { | ||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 48 | 1 | my %hash = ( | |||||||||||||||||||||||||||||||
| 49 | jsonrpc => $self->jsonrpc, | ||||||||||||||||||||||||||||||||
| 50 | method => $self->method, | ||||||||||||||||||||||||||||||||
| 51 | id => $self->id, | ||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||
| 53 | 1 | my $params = $self->params; | |||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $hash{params} = $params if $params && (ref($params) eq 'ARRAY' ? @$params : %$params); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$params and ref $params eq "ARRAY" ? @$params : %$params
MC/DC0%0/2
$params and ref $params eq "ARRAY" ? @$params : %$params
$params
ref $params eq "ARRAY" ? @$params : %$params
Truth table33%1/3
A and B
A= $paramsB= ref $params eq "ARRAY" ? @$params : %$params
| |||||||||||||||||||||||||||||||||
| 55 | 1 | return \%hash; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =pod | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | WWW::MailboxOrg::JSONRPCRequest - JSON-RPC 2.0 request object | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | version 0.001 | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | use WWW::MailboxOrg::JSONRPCRequest; | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | my $req = WWW::MailboxOrg::JSONRPCRequest->new( | ||||||||||||||||||||||||||||||||
| 80 | method => 'account.get', | ||||||||||||||||||||||||||||||||
| 81 | params => { account => 'test@example.tld' }, | ||||||||||||||||||||||||||||||||
| 82 | id => 1, | ||||||||||||||||||||||||||||||||
| 83 | url => 'https://api.mailbox.org/v1', | ||||||||||||||||||||||||||||||||
| 84 | headers => { 'HPLS-AUTH' => 'session123' }, | ||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | Transport-independent JSON-RPC 2.0 request object. | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | =head2 jsonrpc | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | JSON-RPC version. Defaults to "2.0". | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | =head2 method | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | The RPC method name, e.g. "account.get". | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | =head2 params | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | ArrayRef of positional parameters or HashRef of named parameters. | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | =head2 id | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | Request ID for correlating responses. Undef for notifications. | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =head2 url | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | The endpoint URL for the request. | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | =head2 headers | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | Hashref of HTTP headers (e.g. HPLS-AUTH). | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =head2 to_hash | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | Returns a hashref representation for JSON encoding. | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | =head2 Issues | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||
| 124 | L<https://github.com/getty/p5-www-mailboxorg/issues>. | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | =head2 IRC | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | Join C<#perl-help> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 143 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||||||