AtD/Error.pm

filter: Statementstmt 78.7% 26 / 33 Branchbran 33.3% 2 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 75.0% 3 / 4 totaltotal 66.0% 37 / 56 SCAR 17.5
CC
5
Cov
69%
get_suggestions
6.0
BUILD
4.8
has_suggestions
2.0
CRAP 5.7
« AtD/Scores.pm ↑ Summary AtD.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::Error;
10 {
11 6 $Lingua::AtD::Error::VERSION = '1.121570';
12 }
13 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Class::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # ABSTRACT: Encapsulates the grammar/spelling/style Errors contained in Results.
19  
20 {
21  
22 # Attributes
23 6 my %string_of : ATTR( :init_arg<string> :get<string> );
24 6 my %description_of : ATTR( :init_arg<description> :get<description> );
25 6 my %precontext_of : ATTR( :init_arg<precontext> :get<precontext> );
26 6 my %suggestions_of : ATTR();
27 6 my %type_of : ATTR( :init_arg<type> :get<type> );
28 6 my %url_of : ATTR( :get<url> );
29  
30 sub BUILD {
31 2 ▶ my ( $self, $ident, $arg_ref ) = @_;
Subroutine BUILD: called CC=4 SCAR=15.6
Pod undocumented
32  
33 # Special cases. Both are optional, suggestions is an array.
34 $suggestions_of{$ident} = $arg_ref->{suggestions}
35 2 ▶ if ( defined( $arg_ref->{suggestions} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg_ref->{"suggestions"} 2 0 2
36 $url_of{$ident} = $arg_ref->{url}
37 2 ▶ if ( defined( $arg_ref->{url} ) && length( $arg_ref->{url} ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg_ref->{"url"} and length $arg_ref->{"url"} > 0 2 0 2
Condition33%1/3
defined $arg_ref->{"url"} and length $arg_ref->{"url"} > 0
!ll&&!rl&&r
002
MC/DC0%0/2
defined $arg_ref->{"url"} and length $arg_ref->{"url"} > 0
defined $arg_ref->{"url"} length $arg_ref->{"url"} > 0
Truth table33%1/3
A and B
A= defined $arg_ref->{"url"}B= length $arg_ref->{"url"} > 0
ABresult
0X0
100
111
38  
39 2 return;
40 }
41  
42 # Convenience method
43 sub has_suggestions {
44 0 ▶ my $self = shift;
Subroutine has_suggestions: not called CC=1 SCAR=6.9
Pod documented
45 0 return defined( $suggestions_of{ ident($self) } );
46 }
47  
48 # Dereference array
49 sub get_suggestions {
50 0 ▶ my $self = shift;
Subroutine get_suggestions: not called CC=2 SCAR=17.9
Pod documented
51 return $self->has_suggestions()
52 0 ▶ ? @{ $suggestions_of{ ident($self) } }
Branch: 1 branch
BranchTrueFalseTotal
$self->has_suggestions ? : 0 0 0
53 : undef;
54 }
55  
56 # Convenience method
57 sub has_url {
58 0 ▶ my $self = shift;
Subroutine has_url: not called CC=1 SCAR=6.9
Pod documented
59 0 return defined( $url_of{ ident($self) } );
60 }
61  
62 }
63  
64 6 1; # Magic true value required at end of module
65  
66  
67 =pod
68  
69 =head1 NAME
70  
71 Lingua::AtD::Error - Encapsulates the grammar/spelling/style Errors contained in Results.
72  
73 =head1 VERSION
74  
75 version 1.121570
76  
77 =head1 SYNOPSIS
78  
79 use Lingua::AtD;
80  
81 # Create a new service proxy
82 my $atd = Lingua::AtD->new( {
83 host => 'service.afterthedeadline.com',
84 port => 80
85 throttle => 2,
86 });
87  
88 # Run spelling and grammar checks. Returns a Lingua::AtD::Response object.
89 my $doc_check = $atd->check_document('Text to check.');
90 # Loop through reported document errors.
91 foreach my $atd_error ($doc_check->get_errors()) {
92 # Do something with...
93 print "Error string: ", $atd_error->get_string(), "\n";
94 }
95  
96 # Run only grammar checks. Essentially the same as
97 # check_document(), sans spell-check.
98 my $grmr_check = $atd->check_grammar('Text to check.');
99 # Loop through reported document errors.
100 foreach my $atd_error ($grmr_check->get_errors()) {
101 # Do something with...
102 print "Error string: ", $atd_error->get_string(), "\n";
103 }
104  
105 # Get statistics on a document. Returns a Lingua::AtD::Scores object.
106 my $atd_scores = $atd->stats('Text to check.');
107 # Loop through reported document errors.
108 foreach my $atd_metric ($atd_scores->get_metrics()) {
109 # Do something with...
110 print $atd_metric->get_type(), "/", $atd_metric->get_key(),
111 " = ", $atd_metric->get_value(), "\n";
112 }
113  
114 =head1 DESCRIPTION
115  
116 Encapsulates the grammar/spelling/style Errors contained in Results.
117  
118 =head1 METHODS
119  
120 =head2 get_string
121  
122 $atd_error->get_string();
123  
124 Returns the string in error.
125  
126 =head2 get_description
127  
128 $atd_error->get_description();
129  
130 Returns a string description of the error.
131  
132 =head2 get_precontext
133  
134 $atd_error->get_precontext();
135  
136 Returns a string. Usually the word or words immediately preceding the word or phrase in error.
137  
138 =head2 has_suggestions
139  
140 $atd_error->has_suggestions();
141  
142 Returns a boolean (1|0) indicating if the AtD service provided suggestions for fixing the error.
143  
144 =head2 get_suggestions
145  
146 my @suggestions = $atd_error->get_suggestions();
147  
148 In some cases, such as spelling, the AtD service may suggest corrections in the form of an array of strings.
149  
150 =head2 get_type
151  
152 $atd_error->get_type();
153  
154 Returns a string indicating the type of error. One of I<grammar>, I<spelling>, or I<style>.
155  
156 =head2 has_url
157  
158 $atd_error->has_url();
159  
160 Returns a boolean (1|0) indicating if the AtD service provided a URL with more details on the error. This url is suitable for use in UIs.
161  
162 =head2 get_url
163  
164 $atd_error->get_url();
165  
166 Returns a url to the AtD service providing details on the error. This url is suitable for use in UIs.
167  
168 =head1 METHODS
169  
170 =head1 SEE ALSO
171  
172 See the L<API Documentation|http://www.afterthedeadline.com/api.slp> at After the Deadline's website.
173  
174 =head1 AUTHOR
175  
176 David L. Day <dday376@gmail.com>
177  
178 =head1 COPYRIGHT AND LICENSE
179  
180 This software is copyright (c) 2011 by David L. Day.
181  
182 This is free software; you can redistribute it and/or modify it under
183 the same terms as the Perl 5 programming language system itself.
184  
185 =cut
186  
187  
188 __END__
« AtD/Scores.pm ↑ Summary AtD.pm »