blib/lib/XDI/SPIT.pm

filter: Statementstmt 53.8% 28 / 52 Branchbran 16.6% 1 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 100% 5 / 5 totaltotal 52.5% 42 / 80 CC 5 SCAR 13.5
CC
5
Cov
49%
_xriCmd
12.0
resolveBroker
4.0
new
2.0
CRAP 3.9
↑ Summary
1 # XDI::SPIT.pm
2 #
3 # $Id: SPIT.pm,v 1.3 2004/08/03 21:05:36 eekim Exp $
4 #
5 # Copyright (c) Blue Oxen Associates 2004. All rights reserved.
6 #
7 # See COPYING for licensing terms.
8  
9 package XDI::SPIT;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use XRI;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use XRI::Descriptor;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our $VERSION = '1.11';
19  
20 ### constructor
21  
22 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
23 0 bless {}, shift;
24 }
25  
26 ### methods
27  
28 1 ▶sub resolveBroker {
Subroutine resolveBroker: called CC=3 SCAR=13.8
Pod documented
29 1 my $self = shift;
30 1 my $iname = shift;
31  
32 1 my $xri = XRI->new($iname);
33 1 my $xml;
34 1 eval {
35 1 $xml = $xri->resolveToAuthorityXML;
36 };
37 1 ▶ if ($@ || !$xml) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $xml) { } 1 0 1
Condition33%1/3
$@ or not $xml
l!l&&r!l&&!r
100
MC/DC0%0/2
$@ or not $xml
$@ not $xml
Truth table33%1/3
A or not(B)
A= $@B= not $xml
ABresult
1X1
011
000
38 1 return 0;
39 }
40 else {
41 0 my $xriDescriptor = XRI::Descriptor->new($xml);
42 0 my @localAccess = $xriDescriptor->getLocalAccess;
43 0 my $idBroker = ${$localAccess[0]->uris}[0];
44 0 my $inumber = $xriDescriptor->getMappings->[0];
45 0 return $idBroker, $inumber;
46 }
47 }
48  
49 0 ▶sub getAuthUrl {
Subroutine getAuthUrl: not called CC=1 SCAR=6.9
Pod documented
50 0 my $self = shift;
51 0 my ($idBroker, $iname, $returnUrl) = @_;
52  
53 # FIXME: Use inumber instead?
54 0 return "$idBroker?xri_cmd=auth&xri_iname=" . uri_escape($iname) .
55 '&xri_rtn=' . uri_escape($returnUrl);
56 }
57  
58 0 ▶sub validateSession {
Subroutine validateSession: not called CC=1 SCAR=6.9
Pod documented
59 0 my $self = shift;
60 0 my ($idBroker, $iname, $xsid) = @_;
61  
62 0 return &_xriCmd($idBroker, $iname, $xsid, "verify");
63 }
64  
65 0 ▶sub logout {
Subroutine logout: not called CC=1 SCAR=6.9
Pod documented
66 0 my $self = shift;
67 0 my ($idBroker, $iname, $xsid) = @_;
68  
69 0 return &_xriCmd($idBroker, $iname, $xsid, "logout");
70 }
71  
72 ### private methods
73  
74 0 ▶sub _xriCmd {
Subroutine _xriCmd: not called CC=3 SCAR=24.8
75 0 my ($idBroker, $iname, $xsid, $cmd) = @_;
76 0 my $ua = LWP::UserAgent->new;
77 0 $ua->agent("Identity Commons SPIT/$VERSION");
78  
79 0 my $request = HTTP::Request->new(GET=>"$idBroker?xri_cmd=$cmd&xri_iname="
80 . uri_escape($iname) .
81 '&xri_xsid=' . uri_escape($xsid));
82 0 my $response = $ua->request($request);
83 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
84 0 ▶ ($response->content =~ /true/) ? return 1 : return 0;
Branch: 1 branch
BranchTrueFalseTotal
$response->content =~ /true/ ? : 0 0 0
85 }
86 else { # FIXME: should parse status code
87 0 return 0;
88 }
89 }
90  
91 1 1;
92 __END__
↑ Summary