AtD/Results.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 89.6% 69 / 77 CC 8 SCAR 9.2
CC
8
Cov
89%
START
5.2
has_server_exception
2.1
has_errors
2.1
CRAP 2.5
« AtD/Error.pm ↑ Summary AtD/Scores.pm »
1 #
2 # This file is part of Lingua-AtD
3 #
4 # This software is copyright (c) 2011 by David L. Day.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Lingua::AtD::Results;
10 4 $Lingua::AtD::Results::VERSION = '1.160790';
11 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Lingua::AtD::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Lingua::AtD::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Class::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # ABSTRACT: Encapsulate conversion of XML from /checkDocument or /checkGrammar call to Error objects.
20  
21 {
22  
23 # Attributes
24 4 my %xml_of : ATTR( :init_arg<xml> :get<xml> );
25 4 my %server_exception_of : ATTR( :get<server_exception> );
26 4 my %error_count_of : ATTR( :get<error_count> :default<0> );
27 4 my %errors_of : ATTR();
28  
29 1 ▶ sub START {
Subroutine START: called CC=5 SCAR=16.4
Pod undocumented
30 1 my ( $self, $ident, $arg_ref ) = @_;
31 1 my @atd_errors = ();
32  
33 1 my $parser = XML::LibXML->new();
34 1 my $dom = $parser->load_xml( string => $xml_of{$ident} );
35  
36 # Check for server message.
37 1 ▶ if ( $dom->exists('/results/message') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dom->exists("/results/message")) 0 1 1
38 0 $server_exception_of{$ident} = $dom->findvalue('/results/message');
39  
40 # TODO: Implement Exceptions
41 0 croak $server_exception_of{$ident};
42  
43 # Lingua::AtD::ServiceException->throw(
44 # service_message => $server_exception_of{$ident} );
45 }
46  
47 1 foreach my $error_node ( $dom->findnodes('/results/error') ) {
48 2 my @options = ();
49 2 foreach
50 my $option_node ( $error_node->findnodes('./suggestions/option') )
51 {
52 2 push( @options, $option_node->string_value );
53 }
54 2 ▶ my $url =
Branch: 1 branch
BranchTrueFalseTotal
$error_node->exists('url') ? : 2 0 2
55 ( $error_node->exists('url') )
56 ? $error_node->findvalue('url')
57 : undef;
58 2 my $atd_error = Lingua::AtD::Error->new(
59 {
60 string => $error_node->findvalue('string'),
61 description => $error_node->findvalue('description'),
62 precontext => $error_node->findvalue('precontext'),
63 suggestions => [@options],
64 type => $error_node->findvalue('type'),
65 url => $url,
66 }
67 );
68 2 push( @atd_errors, $atd_error );
69 2 $error_count_of{$ident} += 1;
70 }
71 1 $errors_of{$ident} = [@atd_errors];
72  
73 1 return;
74 }
75  
76 1 ▶ sub has_server_exception {
Subroutine has_server_exception: called CC=2 SCAR=7.2
Pod documented
77 1 my $self = shift;
78 1 ▶ return defined( $server_exception_of{ ident($self) } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $server_exception_of{builtin::refaddr($self)} ? : 0 1 1
79 }
80  
81 2 ▶ sub has_errors {
Subroutine has_errors: called CC=2 SCAR=7.2
Pod documented
82 2 my $self = shift;
83  
84 # return defined( $errors_of{ ident($self) } ) ? 1 : 0;
85 2 ▶ return ( $error_count_of{ ident($self) } > 0 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$error_count_of{builtin::refaddr($self)} > 0 ? : 2 0 2
86 }
87  
88 1 ▶ sub get_errors {
Subroutine get_errors: called CC=2 SCAR=7.1
Pod documented
89 1 my $self = shift;
90 return $self->has_errors()
91 1 ▶ ? @{ $errors_of{ ident($self) } }
Branch: 1 branch
BranchTrueFalseTotal
$self->has_errors ? : 1 0 1
92 : undef;
93 }
94  
95 }
96  
97 4 1; # Magic true value required at end of module
98  
99 __END__
« AtD/Error.pm ↑ Summary AtD/Scores.pm »