File Coverage

blib/lib/Konfidi/Response.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             # <@LICENSE>
2             # Licensed under the Apache License, Version 2.0 (the "License");
3             # you may not use this file except in compliance with the License.
4             # You may obtain a copy of the License at
5             #
6             # http://www.apache.org/licenses/LICENSE-2.0
7             #
8             # Unless required by applicable law or agreed to in writing, software
9             # distributed under the License is distributed on an "AS IS" BASIS,
10             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11             # See the License for the specific language governing permissions and
12             # limitations under the License.
13             #
14              
15             package Konfidi::Response;
16              
17 3     3   20 use warnings;
  3         5  
  3         112  
18 3     3   17 use strict;
  3         6  
  3         377  
19              
20             =head1 NAME
21              
22             Konfidi::Response - a Konfidi TrustServer response
23              
24             =head1 DESCRIPTION
25              
26             A hash of values as the response from querying the Konfidi TrustServer. The 'Rating' value is used when a Response is used in a numerical context.
27              
28             =head1 VERSION
29              
30             Version 1.0.4
31              
32             =cut
33              
34             our $VERSION = '1.0.4';
35              
36             =head1 SYNOPSIS
37              
38             use Konfidi::Client;
39             use Konfidi::Response;
40             use Error(:try);
41              
42             my $k = Konfidi::Client->new();
43             $k->server('http://test-server.konfidi.org');
44             try {
45             my $response = $k->query($truster_40char_pgp_fingerprint, $trusted_40char_pgp_fingerprint, 'http://www.konfidi.org/ns/topics/0.0#internet-communication');
46             } catch Konfidi::Client::Error with {
47             my $E = shift;
48             die "Couldn't query the trustserver: $E";
49             };
50            
51             if ($response > 0.5) {
52             ...
53             }
54             $response->{'Subject'};
55             $response->{'Error'};
56             ...
57              
58             =head1 METHODS
59              
60             =head2 C
61              
62             =cut
63              
64 3     3   19 use Carp;
  3         6  
  3         779  
65 3     3   31 use Scalar::Util qw(refaddr);
  3         18  
  3         828  
66              
67             sub new {
68 6     6 1 1600 my $this = shift;
69 6   100     92 my $class = ref($this) || $this;
70 6 100       51 croak unless $class;
71 5         13 my $self = {};
72 5         32 bless $self, $class;
73 5         20 return $self;
74             }
75              
76             sub _numify {
77 1     1   3 my $self = shift;
78 1         120 return $self->{'Rating'};
79             }
80              
81             # overloading 0+ without overloading "" would make stringification requests use numify
82             # so we have to overload ""
83             # this emulates the default "" operator, not sure how to make it actually use the default
84             sub _stringify {
85 2     2   789 my $self = shift;
86 2         48 return ref($self) . '=HASH(0x' . sprintf("%lx",refaddr($self)) . ')';
87             }
88              
89             use overload
90 3         35 '0+' => \&_numify,
91             q("") => \&_stringify,
92 3     3   20 fallback => 1;
  3         5  
93              
94             1;
95              
96             __END__