OcrApi.pm

filter: Statementstmt 25.0% 30 / 120 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 3 totaltotal 22.0% 39 / 177 CC 22 SCAR 46.7
CC
22
Cov
19%
GetRecognizeDocument
210.0
PostOcrFromUrlOrContent
72.0
new
6.0
CRAP 107.2
↑ Summary ApiClient.pm »
1 package AsposeOcrCloud::OcrApi;
2
3 1 require 5.6.0;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 1 ▶use AsposeOcrCloud::ApiClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use AsposeOcrCloud::Configuration;
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 1 my $VERSION = '1.03';
16
17 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $class = shift;
19 0 ▶ my $default_api_client = $AsposeOcrCloud::Configuration::api_client ? $AsposeOcrCloud::Configuration::api_client :
Branch: 1 branch
BranchTrueFalseTotal
$AsposeOcrCloud::Configuration::api_client ? : 0 0 0
20 AsposeOcrCloud::ApiClient->new;
21 0 my (%self) = (
22 'api_client' => $default_api_client,
23 @_
24 );
25
26 #my $self = {
27 # #api_client => $options->{api_client}
28 # api_client => $default_api_client
29 #};
30
31 0 bless \%self, $class;
32
33 }
34
35 #
36 # PostOcrFromUrlOrContent
37 #
38 # Recognize image text from some url if provided or from the request body content, language can be selected, default dictionaries can be used for correction.
39 #
40 # @param String $url The image file url. (optional)
41 # @param String $language Language of the document. (optional)
42 # @param Boolean $useDefaultDictionaries Use default dictionaries for result correction. (optional)
43 # @param File $file (required)
44 # @return OCRResponse
45 #
46 0 ▶sub PostOcrFromUrlOrContent {
Subroutine PostOcrFromUrlOrContent: not called CC=8 SCAR=42.8
Pod undocumented
47 0 my ($self, %args) = @_;
48
49
50 # parse inputs
51 0 my $_resource_path = '/ocr/recognize/?appSid={appSid}&url={url}&language={language}&useDefaultDictionaries={useDefaultDictionaries}';
52
53 0 $_resource_path =~ s/\Q&\E/&/g;
54 0 $_resource_path =~ s/\Q\/?\E/?/g;
55 0 $_resource_path =~ s/\QtoFormat={toFormat}\E/format={format}/g;
56 0 $_resource_path =~ s/\Q{path}\E/{Path}/g;
57
58 0 my $_method = 'POST';
59 0 my $query_params = {};
60 0 my $header_params = {};
61 0 my $form_params = {};
62
63 # 'Accept' and 'Content-Type' header
64 0 my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
65 0 ▶ if ($_header_accept) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_header_accept) 0 0 0
66 0 $header_params->{'Accept'} = $_header_accept;
67 }
68 0 $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('multipart/form-data');
69
70 # query params
71 0 ▶ if ( exists $args{'url'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'url'}) { } 0 0 0
72 0 $_resource_path =~ s/\Q{url}\E/$args{'url'}/g;
73 }else{
74 0 $_resource_path =~ s/[?&]url.*?(?=&|\?|$)//g;
75 }# query params
76 0 ▶ if ( exists $args{'language'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'language'}) { } 0 0 0
77 0 $_resource_path =~ s/\Q{language}\E/$args{'language'}/g;
78 }else{
79 0 $_resource_path =~ s/[?&]language.*?(?=&|\?|$)//g;
80 }# query params
81 0 ▶ if ( exists $args{'useDefaultDictionaries'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'useDefaultDictionaries'}) { } 0 0 0
82 0 $_resource_path =~ s/\Q{useDefaultDictionaries}\E/$args{'useDefaultDictionaries'}/g;
83 }else{
84 0 $_resource_path =~ s/[?&]useDefaultDictionaries.*?(?=&|\?|$)//g;
85 }
86
87
88 0 my $_body_data;
89 # form params
90 0 ▶ if ( exists $args{'file'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"file"}) 0 0 0
91
92 0 $_body_data = read_file( $args{'file'} , binmode => ':raw' );
93
94
95 }
96
97
98
99 # authentication setting, if any
100 0 my $auth_settings = [];
101
102 # make the API Call
103 0 my $response = $self->{api_client}->call_api($_resource_path, $_method,
104 $query_params, $form_params,
105 $header_params, $_body_data, $auth_settings);
106 0 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 0 0
107 0 return;
108 }
109
110 0 ▶ if($AsposeOcrCloud::Configuration::debug){
Branch: 1 branch
BranchTrueFalseTotal
if ($AsposeOcrCloud::Configuration::debug) 0 0 0
111 0 print "\nResponse Content: ".$response->content;
112 }
113
114 0 my $_response_object = $self->{api_client}->pre_deserialize($response->content, 'OCRResponse', $response->header('content-type'));
115 0 return $_response_object;
116
117 }
118 #
119 # GetRecognizeDocument
120 #
121 # Recognize image text, language and text region can be selected, default dictionaries can be used for correction.
122 #
123 # @param String $name Name of the file to recognize. (required)
124 # @param String $language Language of the document. (optional)
125 # @param String $rectX Top left point X coordinate of to recognize text inside. (optional)
126 # @param String $rectY Top left point Y coordinate of to recognize text inside. (optional)
127 # @param String $rectWidth Width of to recognize text inside. (optional)
128 # @param String $rectHeight Height of to recognize text inside. (optional)
129 # @param Boolean $useDefaultDictionaries Use default dictionaries for result correction. (optional)
130 # @param String $storage Image's storage. (optional)
131 # @param String $folder Image's folder. (optional)
132 # @return OCRResponse
133 #
134 0 ▶sub GetRecognizeDocument {
Subroutine GetRecognizeDocument: not called CC=14 SCAR=53.5
Pod undocumented
135 0 my ($self, %args) = @_;
136
137
138 # verify the required parameter 'name' is set
139 0 ▶ unless (exists $args{'name'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"name"}) 0 0 0
140 0 croak("Missing the required parameter 'name' when calling GetRecognizeDocument");
141 }
142
143
144 # parse inputs
145 0 my $_resource_path = '/ocr/{name}/recognize/?appSid={appSid}&language={language}&rectX={rectX}&rectY={rectY}&rectWidth={rectWidth}&rectHeight={rectHeight}&useDefaultDictionaries={useDefaultDictionaries}&storage={storage}&folder={folder}';
146
147 0 $_resource_path =~ s/\Q&\E/&/g;
148 0 $_resource_path =~ s/\Q\/?\E/?/g;
149 0 $_resource_path =~ s/\QtoFormat={toFormat}\E/format={format}/g;
150 0 $_resource_path =~ s/\Q{path}\E/{Path}/g;
151
152 0 my $_method = 'GET';
153 0 my $query_params = {};
154 0 my $header_params = {};
155 0 my $form_params = {};
156
157 # 'Accept' and 'Content-Type' header
158 0 my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
159 0 ▶ if ($_header_accept) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_header_accept) 0 0 0
160 0 $header_params->{'Accept'} = $_header_accept;
161 }
162 0 $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json');
163
164 # query params
165 0 ▶ if ( exists $args{'name'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'name'}) { } 0 0 0
166 0 $_resource_path =~ s/\Q{name}\E/$args{'name'}/g;
167 }else{
168 0 $_resource_path =~ s/[?&]name.*?(?=&|\?|$)//g;
169 }# query params
170 0 ▶ if ( exists $args{'language'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'language'}) { } 0 0 0
171 0 $_resource_path =~ s/\Q{language}\E/$args{'language'}/g;
172 }else{
173 0 $_resource_path =~ s/[?&]language.*?(?=&|\?|$)//g;
174 }# query params
175 0 ▶ if ( exists $args{'rectX'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'rectX'}) { } 0 0 0
176 0 $_resource_path =~ s/\Q{rectX}\E/$args{'rectX'}/g;
177 }else{
178 0 $_resource_path =~ s/[?&]rectX.*?(?=&|\?|$)//g;
179 }# query params
180 0 ▶ if ( exists $args{'rectY'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'rectY'}) { } 0 0 0
181 0 $_resource_path =~ s/\Q{rectY}\E/$args{'rectY'}/g;
182 }else{
183 0 $_resource_path =~ s/[?&]rectY.*?(?=&|\?|$)//g;
184 }# query params
185 0 ▶ if ( exists $args{'rectWidth'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'rectWidth'}) { } 0 0 0
186 0 $_resource_path =~ s/\Q{rectWidth}\E/$args{'rectWidth'}/g;
187 }else{
188 0 $_resource_path =~ s/[?&]rectWidth.*?(?=&|\?|$)//g;
189 }# query params
190 0 ▶ if ( exists $args{'rectHeight'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'rectHeight'}) { } 0 0 0
191 0 $_resource_path =~ s/\Q{rectHeight}\E/$args{'rectHeight'}/g;
192 }else{
193 0 $_resource_path =~ s/[?&]rectHeight.*?(?=&|\?|$)//g;
194 }# query params
195 0 ▶ if ( exists $args{'useDefaultDictionaries'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'useDefaultDictionaries'}) { } 0 0 0
196 0 $_resource_path =~ s/\Q{useDefaultDictionaries}\E/$args{'useDefaultDictionaries'}/g;
197 }else{
198 0 $_resource_path =~ s/[?&]useDefaultDictionaries.*?(?=&|\?|$)//g;
199 }# query params
200 0 ▶ if ( exists $args{'storage'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'storage'}) { } 0 0 0
201 0 $_resource_path =~ s/\Q{storage}\E/$args{'storage'}/g;
202 }else{
203 0 $_resource_path =~ s/[?&]storage.*?(?=&|\?|$)//g;
204 }# query params
205 0 ▶ if ( exists $args{'folder'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'folder'}) { } 0 0 0
206 0 $_resource_path =~ s/\Q{folder}\E/$args{'folder'}/g;
207 }else{
208 0 $_resource_path =~ s/[?&]folder.*?(?=&|\?|$)//g;
209 }
210
211
212 0 my $_body_data;
213
214
215
216
217 # authentication setting, if any
218 0 my $auth_settings = [];
219
220 # make the API Call
221 0 my $response = $self->{api_client}->call_api($_resource_path, $_method,
222 $query_params, $form_params,
223 $header_params, $_body_data, $auth_settings);
224 0 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 0 0
225 0 return;
226 }
227
228 0 ▶ if($AsposeOcrCloud::Configuration::debug){
Branch: 1 branch
BranchTrueFalseTotal
if ($AsposeOcrCloud::Configuration::debug) 0 0 0
229 0 print "\nResponse Content: ".$response->content;
230 }
231
232 0 my $_response_object = $self->{api_client}->pre_deserialize($response->content, 'OCRResponse', $response->header('content-type'));
233 0 return $_response_object;
234
235 }
236
237
238 1 1;
↑ Summary ApiClient.pm »