| 1 | package Net::OpenSocial::Client::Protocol::Builder; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use OAuth::Lite::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::OpenSocial::Client::HTTPRequestBuilder::OAuth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::OpenSocial::Client::HTTPRequestBuilder::ST; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Net::OpenSocial::Client::Protocol::REST; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Net::OpenSocial::Client::Protocol::RPC; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Net::OpenSocial::Client::Formatter::JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Net::OpenSocial::Client::Type::Protocol qw(REST RPC); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Net::OpenSocial::Client::Type::Auth qw(OAUTH ST); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Net::OpenSocial::Client::Type::Format qw(JSON XML ATOM); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | with 'Net::OpenSocial::Client::ErrorHandler'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | has 'protocol_type' => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | isa => 'Str', | ||||||||||||||||||||||||||||
| 24 | default => REST, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | has 'auth_type' => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => 'Str', | ||||||||||||||||||||||||||||
| 30 | default => OAUTH, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | has 'format_type' => ( | |||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | isa => 'Str', | ||||||||||||||||||||||||||||
| 36 | default => JSON, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | has 'consumer_key' => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => 'Str', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | has 'consumer_secret' => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | isa => 'Str', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | has 'token' => ( | |||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||
| 51 | isa => 'OAuth::Lite::Token', | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | has 'requestor' => ( | |||||||||||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||||||||||
| 56 | isa => 'Str', | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | has 'st' => ( | |||||||||||||||||||||||||||
| 60 | is => 'ro', | ||||||||||||||||||||||||||||
| 61 | isa => 'Str', | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | has 'agent' => ( | ||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | default => sub { LWP::UserAgent->new }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 1 | ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub build_protocol { | ||||||||||||||||||||||||||
|
Subroutine
build_protocol: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $request_builder = $self->_build_request_builder() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | or return; | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $formatter = $self->_build_formatter() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | or return; | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $self->protocol_type eq REST ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 76 | 0 | return Net::OpenSocial::Client::Protocol::REST->new( | |||||||||||||||||||||||||||
| 77 | request_builder => $request_builder, | ||||||||||||||||||||||||||||
| 78 | formatter => $formatter, | ||||||||||||||||||||||||||||
| 79 | agent => $self->agent, | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | elsif ( $self->protocol_type eq RPC ) { | ||||||||||||||||||||||||||||
| 83 | 0 | return Net::OpenSocial::Client::Protocol::RPC->new( | |||||||||||||||||||||||||||
| 84 | request_builder => $request_builder, | ||||||||||||||||||||||||||||
| 85 | formatter => $formatter, | ||||||||||||||||||||||||||||
| 86 | agent => $self->agent, | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 0 | return $self->ERROR(q{Unknown protocol type.}); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _build_formatter { | ||||||||||||||||||||||||||
|
Subroutine
_build_formatter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 93 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( $self->format_type eq JSON ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | return Net::OpenSocial::Client::Formatter::JSON->new; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # XXX: not supported yet | ||||||||||||||||||||||||||||
| 99 | #elsif ( $self->format_type eq XML ) { | ||||||||||||||||||||||||||||
| 100 | # return Net::OpenSocial::Client::Formatter::XML->new; | ||||||||||||||||||||||||||||
| 101 | #} | ||||||||||||||||||||||||||||
| 102 | #elsif ( $self->format_type eq ATOM ) { | ||||||||||||||||||||||||||||
| 103 | # return $self->ERROR(q{Atom format is not supported on RPC protocol.}) | ||||||||||||||||||||||||||||
| 104 | # if ( $self->protocol_type eq RPC ); | ||||||||||||||||||||||||||||
| 105 | # return Net::OpenSocial::Client::Formatter::Atom->new; | ||||||||||||||||||||||||||||
| 106 | #} | ||||||||||||||||||||||||||||
| 107 | 0 | return $self->ERROR(q{Unknown format type.}); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub _build_request_builder { | ||||||||||||||||||||||||||
|
Subroutine
_build_request_builder: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $self->auth_type eq OAUTH ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $self->ERROR( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->consumer_key and defined $self->consumer_secret
MC/DC0%0/2
defined $self->consumer_key and defined $self->consumer_secret
defined $self->consumer_key
defined $self->consumer_secret
Truth table0%0/3
A and B
A= defined $self->consumer_keyB= defined $self->consumer_secret
| |||||||||||||||||||||||||||||
| 114 | q{When you set OAUTH as auth_type, you should set both 'consumer_key' and 'consumer_secret'.} | ||||||||||||||||||||||||||||
| 115 | ) | ||||||||||||||||||||||||||||
| 116 | unless ( defined $self->consumer_key | ||||||||||||||||||||||||||||
| 117 | && defined $self->consumer_secret ); | ||||||||||||||||||||||||||||
| 118 | 0 | my %args = ( | |||||||||||||||||||||||||||
| 119 | consumer_key => $self->consumer_key, | ||||||||||||||||||||||||||||
| 120 | consumer_secret => $self->consumer_secret, | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $self->token ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 123 | 0 | $args{token} = $self->token; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | elsif ( $self->requestor ) { | ||||||||||||||||||||||||||||
| 126 | 0 | $args{requestor} = $self->requestor; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 0 | return Net::OpenSocial::Client::HTTPRequestBuilder::OAuth->new(%args); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | elsif ( $self->auth_type eq ST ) { | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return $self->ERROR( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | q{When you set ST as auth_type, you should set parameter 'st' for security token value.} | ||||||||||||||||||||||||||||
| 133 | ) unless ( defined $self->st ); | ||||||||||||||||||||||||||||
| 134 | 0 | return Net::OpenSocial::Client::HTTPRequestBuilder::ST->new( | |||||||||||||||||||||||||||
| 135 | st => $self->st ); | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 0 | return $self->ERROR(q{Unknown auth type.}); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 1 | ▶ | no Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 142 | 1 | 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head1 NAME | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Net::OpenSocial::Client::Protocol::Builder - Protocol builder | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | my $builder = Net::OpenSocial::Client::Protocol::Builder->new(); | ||||||||||||||||||||||||||||
| 151 | my $protocol = $builder->build_protocol(); | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Protocol builder. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 METHODS | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 build_protocol | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | L<Net::OpenSocial::Client> | ||||||||||||||||||||||||||||
| 164 | L<Net::OpenSocial::Client::Protocol> | ||||||||||||||||||||||||||||
| 165 | L<Net::OpenSocial::Client::Protocol::REST> | ||||||||||||||||||||||||||||
| 166 | L<Net::OpenSocial::Client::Protocol::RPC> | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | Copyright (C) 2009 by Lyo Kato | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 177 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 178 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||