| 1 | package Mail::Karmasphere::Response; | ||||||||||
| 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 | 5 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 8 | 0 | my $class = shift; | |||||||||
| 9 | 0 | ▶ | my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | 0 | return bless $self, $class; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub id { | ||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 14 | 0 | my ($self) = @_; | |||||||||
| 15 | 0 | ▶ | $self->{_} = '???' unless defined $self->{_}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | return $self->{_}; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub time { | ||||||||
|
Subroutine
time: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 20 | 0 | my $self = shift; | |||||||||
| 21 | 0 | ▶ | return $self->{t} if defined $self->{t}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | ▶ | return $self->{'time'} if defined $self->{'time'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | return '???'; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # deprecated | ||||||||||
| 27 | 0 | ▶ | sub facts { | ||||||||
|
Subroutine
facts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 28 | 0 | my $self = shift; | |||||||||
| 29 | 0 | ▶ | return $self->{f} if exists $self->{f}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | ▶ | return $self->{facts} if exists $self->{facts}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $self->{f} = []; | |||||||||
| 32 | 0 | return $self->{f}; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub attributes { | ||||||||
|
Subroutine
attributes: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 36 | 0 | my $self = shift; | |||||||||
| 37 | 0 | ▶ | return $self->{f} if exists $self->{f}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | ▶ | return $self->{facts} if exists $self->{facts}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | $self->{f} = []; | |||||||||
| 40 | 0 | return $self->{f}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub combinations { | ||||||||
|
Subroutine
combinations: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 44 | 0 | my $self = shift; | |||||||||
| 45 | 0 | ▶ | return $self->{c} if exists $self->{c}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | return $self->{combiners} if exists $self->{combiners}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $self->{c} = {}; | |||||||||
| 48 | 0 | return $self->{c}; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub combination { | ||||||||
|
Subroutine
combination: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 52 | 0 | my ($self, $combiner) = @_; | |||||||||
| 53 | 0 | ▶ | return () unless $self->combinations; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return $self->combinations->{$combiner}; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub combiner_names { | ||||||||
|
Subroutine
combiner_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 58 | 0 | my ($self) = @_; | |||||||||
| 59 | 0 | ▶ | return () unless $self->combinations; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return keys %{ $self->combinations }; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub _combination_get { | ||||||||
|
Subroutine
_combination_get: not called CC=7 SCAR=40.3
| |||||||||||
| 64 | 0 | my ($self, $key, $combiner) = @_; | |||||||||
| 65 | 0 | ▶ | return undef unless $self->combinations; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | if ($combiner) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | my $combination = $self->combination($combiner); | |||||||||
| 68 | 0 | ▶ | return undef unless $combination; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | return $combination->{$key}; | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | my $combination = $self->combination('default'); | |||||||||
| 72 | 0 | ▶ | if ($combination) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | return $combination->{$key}; | |||||||||
| 74 | } | ||||||||||
| 75 | 0 | foreach (values %{ $self->combinations }) { | |||||||||
| 76 | 0 | ▶ | return $_->{$key} if exists $_->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | } | ||||||||||
| 78 | 0 | return undef; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub value { | ||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 82 | 0 | my $self = shift; | |||||||||
| 83 | 0 | return $self->_combination_get('v', @_); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub data { | ||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | my $self = shift; | |||||||||
| 88 | 0 | return $self->_combination_get('d', @_); | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub error { | ||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 92 | 0 | return $_[0]->{error}; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | sub message { | ||||||||
|
Subroutine
message: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 96 | 0 | return $_[0]->{message}; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||
| 100 | 0 | my ($self) = @_; | |||||||||
| 101 | 0 | my $out = "Response id '" . $self->id . "': "; | |||||||||
| 102 | 0 | $out = $out . $self->time . "ms, "; | |||||||||
| 103 | 0 | my @names = $self->combiner_names; | |||||||||
| 104 | 0 | $out = $out . scalar(@names) . " verdicts, "; | |||||||||
| 105 | 0 | $out = $out . scalar(@{ $self->facts }) . " attributes\n"; | |||||||||
| 106 | 0 | ▶ | if ($self->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 0 | $out .= "Error: " . $self->message . "\n"; | |||||||||
| 108 | } | ||||||||||
| 109 | else { | ||||||||||
| 110 | 0 | ▶ | if ($self->message) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | $out .= "Warning: " . $self->message . "\n"; | |||||||||
| 112 | } | ||||||||||
| 113 | 0 | foreach (sort @names) { | |||||||||
| 114 | 0 | my $value = $self->value($_); | |||||||||
| 115 | 0 | my $data = $self->data($_); | |||||||||
| 116 | 0 | ▶ | $value = 0 unless defined $value; # Might happen | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | ▶ | $data = '(undef)' unless defined $data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | $out .= "Combiner '$_': verdict $value ($data)\n"; | |||||||||
| 119 | } | ||||||||||
| 120 | 0 | my @facts = sort { $a->{f} cmp $b->{f} } @{$self->facts}; | |||||||||
| 121 | 0 | foreach (@facts) { | |||||||||
| 122 | 0 | my $d = $_->{d}; | |||||||||
| 123 | 0 | ▶ | $d = "null data" unless defined $d; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | $out .= "Attribute '$_->{f}':"; | |||||||||
| 125 | 0 | ▶ | $out .= " identity '$_->{i}'" if exists $_->{i}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | $out .= " value $_->{v} ($d)\n"; | |||||||||
| 127 | } | ||||||||||
| 128 | } | ||||||||||
| 129 | 0 | return $out; | |||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | =head1 NAME | ||||||||||
| 133 | |||||||||||
| 134 | Mail::Karmasphere::Response - Karmasphere Response Object | ||||||||||
| 135 | |||||||||||
| 136 | =head1 SYNOPSIS | ||||||||||
| 137 | |||||||||||
| 138 | See Mail::Karmasphere::Client | ||||||||||
| 139 | |||||||||||
| 140 | =head1 DESCRIPTION | ||||||||||
| 141 | |||||||||||
| 142 | The Perl Karma Client API consists of three objects: The Query, the | ||||||||||
| 143 | Response and the Client. The user constructs a Query and passes it to | ||||||||||
| 144 | a Client, which returns a Response. See L<Mail::Karmasphere::Client> | ||||||||||
| 145 | for more information. | ||||||||||
| 146 | |||||||||||
| 147 | =head1 METHODS | ||||||||||
| 148 | |||||||||||
| 149 | =over 4 | ||||||||||
| 150 | |||||||||||
| 151 | =item $response->facts() | ||||||||||
| 152 | |||||||||||
| 153 | Returns a list of fact data. | ||||||||||
| 154 | |||||||||||
| 155 | =item $response->combination($name) | ||||||||||
| 156 | |||||||||||
| 157 | Returns the named combination as a hash reference. | ||||||||||
| 158 | |||||||||||
| 159 | =item $response->value($name) | ||||||||||
| 160 | |||||||||||
| 161 | Returns the value of the named combination. | ||||||||||
| 162 | |||||||||||
| 163 | If no combiner name is given, this method looks for a combination | ||||||||||
| 164 | called 'default', if present, otherwise searches for the first | ||||||||||
| 165 | available combination with a value. | ||||||||||
| 166 | |||||||||||
| 167 | If $name is given, this is equivalent (but preferable) to | ||||||||||
| 168 | $response->combination($name)->{v}. | ||||||||||
| 169 | |||||||||||
| 170 | =item $response->data($name) | ||||||||||
| 171 | |||||||||||
| 172 | Returns the data of the named combination. | ||||||||||
| 173 | |||||||||||
| 174 | The rules for choosing a combination are the same as those for | ||||||||||
| 175 | $response->value($name). | ||||||||||
| 176 | |||||||||||
| 177 | =item $response->id() | ||||||||||
| 178 | |||||||||||
| 179 | Returns the id of this response. It will match the id passed in the | ||||||||||
| 180 | query, which was either specified by the user or generated by the | ||||||||||
| 181 | client. | ||||||||||
| 182 | |||||||||||
| 183 | =item $response->time() | ||||||||||
| 184 | |||||||||||
| 185 | Returns the time in milliseconds taken by this request. | ||||||||||
| 186 | |||||||||||
| 187 | =back | ||||||||||
| 188 | |||||||||||
| 189 | =head1 BUGS | ||||||||||
| 190 | |||||||||||
| 191 | This document is incomplete. | ||||||||||
| 192 | |||||||||||
| 193 | =head1 SEE ALSO | ||||||||||
| 194 | |||||||||||
| 195 | L<Mail::Karmasphere::Client> | ||||||||||
| 196 | L<Mail::Karmasphere::Query> | ||||||||||
| 197 | http://www.karmasphere.com/ | ||||||||||
| 198 | |||||||||||
| 199 | =head1 COPYRIGHT | ||||||||||
| 200 | |||||||||||
| 201 | Copyright (c) 2005 Shevek, Karmasphere. All rights reserved. | ||||||||||
| 202 | |||||||||||
| 203 | This program is free software; you can redistribute it and/or modify | ||||||||||
| 204 | it under the same terms as Perl itself. | ||||||||||
| 205 | |||||||||||
| 206 | =cut | ||||||||||
| 207 | |||||||||||
| 208 | 5 | 1; | |||||||||