File Coverage

blib/lib/WebService/Lucene/Exception.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package WebService::Lucene::Exception;
2              
3 1     1   1981 use strict;
  1         3  
  1         46  
4 1     1   6 use warnings;
  1         2  
  1         42  
5              
6 1         10 use Exception::Class 'WebService::Lucene::Exception' =>
7 1     1   929 { fields => [ qw( response entry stacktrace type ) ] };
  1         22116  
8 1     1   420 use base qw( Exception::Class::Base );
  1         2  
  1         32  
9              
10 1     1   535 use XML::Atom::Entry;
  0            
  0            
11              
12             =head1 NAME
13              
14             WebService::Lucene::Exception - Exceptions to catch from the web service
15              
16             =head1 SYNOPSIS
17              
18             my $entry = eval { $index->get_document( 1 ); };
19             if( my $e = WebService::Lucene::Exception->caught ) {
20             # handle exception
21             }
22              
23             =head1 DESCRIPTION
24              
25             Object thrown for all exceptions from the web service.
26              
27             =head1 METHODS
28              
29             =head2 new( $reponse )
30              
31             Constructs a new exception from an HTTP::Response.
32              
33             =cut
34              
35             sub new {
36             my ( $class, $response ) = @_;
37             my $self = $class->SUPER::new;
38              
39             $self->{ response } = $response;
40              
41             my $entry = eval { XML::Atom::Entry->new( \$response->content ) };
42              
43             # if lucene-ws is broken, we won't get an XML::Atom::Entry
44             if ( !$entry ) {
45             $self->{ message } = $response->message;
46             return $self;
47             }
48              
49             $self->{ entry } = $entry;
50             $self->{ message } = $entry->summary;
51             $self->{ type } = $entry->title;
52              
53             my $content = $entry->content;
54             if ( $content->type eq 'html' ) {
55             $self->{ statcktrace } = $content->body;
56             }
57              
58             return $self;
59             }
60              
61             =head2 response ( )
62              
63             The L object passed to this exception.
64              
65             =head2 entry( )
66              
67             The XML::Atom Entry for the error returned from the server.
68              
69             =head2 stacktrace( )
70              
71             If debug mode is enabled, a full stracktrace from the server-side will
72             be found here.
73              
74             =head2 type ( )
75              
76             Returns the type of exception the lucene web service has thrown.
77              
78             =head2 Fields( )
79              
80             Subclassed method to store an arrayref of extra fields.
81              
82             =head1 AUTHORS
83              
84             =over 4
85              
86             =item * Brian Cassidy Ebrian.cassidy@nald.caE
87              
88             =item * Adam Paynter Eadam.paynter@nald.caE
89              
90             =back
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             Copyright 2006-2009 National Adult Literacy Database
95              
96             This library is free software; you can redistribute it and/or modify
97             it under the same terms as Perl itself.
98              
99             =cut
100              
101             1;