line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siffra::Tools; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
70648
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
7
|
1
|
|
|
1
|
|
616
|
use utf8; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
699
|
use Data::Dumper; |
|
1
|
|
|
|
|
6943
|
|
|
1
|
|
|
|
|
60
|
|
9
|
1
|
|
|
1
|
|
453
|
use DDP; |
|
1
|
|
|
|
|
42259
|
|
|
1
|
|
|
|
|
11
|
|
10
|
1
|
|
|
1
|
|
652
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
10866
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
2214
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
12
|
|
|
|
|
|
|
$Carp::Verbose = 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$| = 1; #autoflush |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use constant { |
17
|
|
|
|
|
|
|
FALSE => 0, |
18
|
|
|
|
|
|
|
TRUE => 1, |
19
|
1
|
|
50
|
|
|
110
|
DEBUG => $ENV{ DEBUG } // 0, |
20
|
1
|
|
|
1
|
|
42
|
}; |
|
1
|
|
|
|
|
3
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
478
|
use MIME::Types; |
|
1
|
|
|
|
|
4210
|
|
|
1
|
|
|
|
|
49
|
|
23
|
1
|
|
|
1
|
|
684
|
use IO::Uncompress::Unzip qw(unzip $UnzipError); |
|
1
|
|
|
|
|
66873
|
|
|
1
|
|
|
|
|
189
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %driverConnections = ( |
26
|
|
|
|
|
|
|
pgsql => { |
27
|
|
|
|
|
|
|
module => 'DBD::Pg', |
28
|
|
|
|
|
|
|
dsn => 'DBI:Pg(AutoCommit=>1,RaiseError=>1,PrintError=>1):dbname=%s;host=%s;port=%s', |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
mysql => { |
31
|
|
|
|
|
|
|
module => 'DBD::mysql', |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
sqlite => { |
34
|
|
|
|
|
|
|
module => 'DBD::SQLite', |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
BEGIN |
39
|
|
|
|
|
|
|
{ |
40
|
1
|
|
|
1
|
|
20
|
binmode( STDOUT, ":encoding(UTF-8)" ); |
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
41
|
1
|
|
|
|
|
17054
|
binmode( STDERR, ":encoding(UTF-8)" ); |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
502
|
require Siffra::Base; |
44
|
1
|
|
|
1
|
|
11
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
45
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
109
|
|
46
|
1
|
|
|
|
|
1945
|
$VERSION = '0.27'; |
47
|
1
|
|
|
|
|
21
|
@ISA = qw(Siffra::Base Exporter); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
50
|
1
|
|
|
|
|
5
|
@EXPORT = qw(); |
51
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw(); |
52
|
1
|
|
|
|
|
3950
|
%EXPORT_TAGS = (); |
53
|
|
|
|
|
|
|
} ## end BEGIN |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#################### subroutine header begin #################### |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 sample_function |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Usage : How to use this function/method |
60
|
|
|
|
|
|
|
Purpose : What it does |
61
|
|
|
|
|
|
|
Returns : What it returns |
62
|
|
|
|
|
|
|
Argument : What it wants to know |
63
|
|
|
|
|
|
|
Throws : Exceptions and other anomolies |
64
|
|
|
|
|
|
|
Comment : This is a sample subroutine header. |
65
|
|
|
|
|
|
|
: It is polite to include more pod and fewer comments. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
See Also : |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#################### subroutine header end #################### |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 C<new()> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Usage : $self->block_new_method() within text_pm_file() |
76
|
|
|
|
|
|
|
Purpose : Build 'new()' method as part of a pm file |
77
|
|
|
|
|
|
|
Returns : String holding sub new. |
78
|
|
|
|
|
|
|
Argument : $module: pointer to the module being built |
79
|
|
|
|
|
|
|
(as there can be more than one module built by EU::MM); |
80
|
|
|
|
|
|
|
for the primary module it is a pointer to $self |
81
|
|
|
|
|
|
|
Throws : n/a |
82
|
|
|
|
|
|
|
Comment : This method is a likely candidate for alteration in a subclass, |
83
|
|
|
|
|
|
|
e.g., pass a single hash-ref to new() instead of a list of |
84
|
|
|
|
|
|
|
parameters. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub new |
89
|
|
|
|
|
|
|
{ |
90
|
1
|
|
|
1
|
1
|
94
|
$log->debug( "new", { progname => $0, pid => $$, perl_version => $], package => __PACKAGE__ } ); |
91
|
1
|
|
|
|
|
7
|
my ( $class, %parameters ) = @_; |
92
|
1
|
|
|
|
|
12
|
my $self = $class->SUPER::new( %parameters ); |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
21
|
return $self; |
95
|
|
|
|
|
|
|
} ## end sub new |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _initialize() |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
|
0
|
$log->debug( "_initialize", { package => __PACKAGE__ } ); |
100
|
0
|
|
|
|
|
0
|
my ( $self, %parameters ) = @_; |
101
|
0
|
|
|
|
|
0
|
$self->SUPER::_initialize( %parameters ); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
eval { require JSON::XS; }; |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
|
|
|
|
0
|
$self->{ json } = JSON::XS->new->utf8; |
105
|
|
|
|
|
|
|
} ## end sub _initialize |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _finalize() |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
|
0
|
$log->debug( "_finalize", { package => __PACKAGE__ } ); |
110
|
0
|
|
|
|
|
0
|
my ( $self, %parameters ) = @_; |
111
|
0
|
|
|
|
|
0
|
$self->SUPER::_finalize( %parameters ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub END |
115
|
|
|
|
|
|
|
{ |
116
|
1
|
|
|
1
|
|
151
|
$log->debug( "END", { package => __PACKAGE__ } ); |
117
|
1
|
|
|
|
|
4
|
eval { $log->{ adapter }->{ dispatcher }->{ outputs }->{ Email }->flush; }; |
|
1
|
|
|
|
|
66
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub DESTROY |
121
|
|
|
|
|
|
|
{ |
122
|
1
|
|
|
1
|
|
575
|
my ( $self, %parameters ) = @_; |
123
|
1
|
|
|
|
|
10
|
$log->debug( 'DESTROY', { package => __PACKAGE__, GLOBAL_PHASE => ${^GLOBAL_PHASE}, blessed => FALSE } ); |
124
|
1
|
50
|
|
|
|
8
|
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
33
|
|
|
12
|
if ( blessed( $self ) && $self->isa( __PACKAGE__ ) ) |
127
|
|
|
|
|
|
|
{ |
128
|
1
|
|
|
|
|
6
|
$log->debug( "DESTROY", { package => __PACKAGE__, GLOBAL_PHASE => ${^GLOBAL_PHASE}, blessed => TRUE } ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else |
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
# TODO |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} ## end sub DESTROY |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 C<connectDB()> |
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub connectDB() |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
142
|
0
|
|
|
|
|
|
$log->debug( "connectDB", { package => __PACKAGE__ } ); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my ( $database, $host, $password, $port, $username, $connection ); |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ( %parameters ) |
|
|
0
|
|
|
|
|
|
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
|
|
|
$connection = $parameters{ connection }; |
149
|
0
|
|
|
|
|
|
$database = $parameters{ database }; |
150
|
0
|
|
|
|
|
|
$host = $parameters{ host }; |
151
|
0
|
|
|
|
|
|
$password = $parameters{ password }; |
152
|
0
|
|
|
|
|
|
$port = $parameters{ port }; |
153
|
0
|
|
|
|
|
|
$username = $parameters{ username }; |
154
|
|
|
|
|
|
|
} ## end if ( %parameters ) |
155
|
|
|
|
|
|
|
elsif ( defined $self->{ configurations }->{ database } ) |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
|
|
|
$connection = $self->{ configurations }->{ database }->{ connection }; |
158
|
0
|
|
|
|
|
|
$database = $self->{ configurations }->{ database }->{ database }; |
159
|
0
|
|
|
|
|
|
$host = $self->{ configurations }->{ database }->{ host }; |
160
|
0
|
|
|
|
|
|
$password = $self->{ configurations }->{ database }->{ password }; |
161
|
0
|
|
|
|
|
|
$port = $self->{ configurations }->{ database }->{ port }; |
162
|
0
|
|
|
|
|
|
$username = $self->{ configurations }->{ database }->{ username }; |
163
|
|
|
|
|
|
|
} ## end elsif ( defined $self->{ ...}) |
164
|
|
|
|
|
|
|
else |
165
|
|
|
|
|
|
|
{ |
166
|
0
|
|
|
|
|
|
$log->error( "Tentando conectar mas sem configuração de DB..." ); |
167
|
0
|
|
|
|
|
|
return FALSE; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $driverConnection = $driverConnections{ lc $connection }; |
171
|
0
|
0
|
|
|
|
|
if ( $driverConnection ) |
172
|
|
|
|
|
|
|
{ |
173
|
0
|
|
|
|
|
|
eval { |
174
|
0
|
|
|
|
|
|
require DBI; |
175
|
0
|
|
|
|
|
|
require "$driverConnection->{ module }"; |
176
|
|
|
|
|
|
|
}; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $dsn = sprintf( $driverConnection->{ dsn }, $database, $host, $port ); |
179
|
0
|
0
|
|
|
|
|
my ( $scheme, $driver, $attr_string, $attr_hash, $driver_dsn ) = DBI->parse_dsn( $dsn ) or die "Can't parse DBI DSN '$dsn'"; |
180
|
0
|
|
|
|
|
|
my $data_source = "$scheme:$driver:$driver_dsn"; |
181
|
0
|
|
|
|
|
|
$log->info( $data_source ); |
182
|
0
|
|
|
|
|
|
$log->info( "Conectando no banco $username\@$host\:$database" ); |
183
|
0
|
|
|
|
|
|
$self->{ database }->{ connection } = eval { DBI->connect( $data_source, $username, $password, $attr_hash ); }; |
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if ( $@ ) |
186
|
|
|
|
|
|
|
{ |
187
|
0
|
|
|
|
|
|
$log->error( "Erro ao conectar ao banco [ $data_source ] [ $username\@$host:$port ]." ); |
188
|
0
|
|
|
|
|
|
$log->error( @_ ); |
189
|
0
|
|
|
|
|
|
return FALSE; |
190
|
|
|
|
|
|
|
} ## end if ( $@ ) |
191
|
|
|
|
|
|
|
} ## end if ( $driverConnection...) |
192
|
|
|
|
|
|
|
else |
193
|
|
|
|
|
|
|
{ |
194
|
0
|
|
|
|
|
|
$log->error( "Connection [ $connection ] não existe configuração..." ); |
195
|
0
|
|
|
|
|
|
return FALSE; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
return $self->{ database }->{ connection }; |
199
|
|
|
|
|
|
|
} ## end sub connectDB |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 C<begin_work()> |
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub begin_work() |
205
|
|
|
|
|
|
|
{ |
206
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
207
|
0
|
0
|
|
|
|
|
if ( !defined $self->{ database }->{ connection } ) |
208
|
|
|
|
|
|
|
{ |
209
|
0
|
|
|
|
|
|
$log->error( "Tentando começar uma transação sem uma conexão com DB..." ); |
210
|
0
|
|
|
|
|
|
return FALSE; |
211
|
|
|
|
|
|
|
} |
212
|
0
|
0
|
|
|
|
|
my $rc = $self->{ database }->{ connection }->begin_work or die $self->{ database }->{ connection }->errstr; |
213
|
0
|
|
|
|
|
|
return $rc; |
214
|
|
|
|
|
|
|
} ## end sub begin_work |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 C<commit()> |
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub commit() |
220
|
|
|
|
|
|
|
{ |
221
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
222
|
0
|
0
|
|
|
|
|
if ( !defined $self->{ database }->{ connection } ) |
223
|
|
|
|
|
|
|
{ |
224
|
0
|
|
|
|
|
|
$log->error( "Tentando commitar uma transação sem uma conexão com DB..." ); |
225
|
0
|
|
|
|
|
|
return FALSE; |
226
|
|
|
|
|
|
|
} |
227
|
0
|
0
|
|
|
|
|
my $rc = $self->{ database }->{ connection }->commit or die $self->{ database }->{ connection }->errstr; |
228
|
0
|
|
|
|
|
|
return $rc; |
229
|
|
|
|
|
|
|
} ## end sub commit |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 C<rollback()> |
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub rollback() |
235
|
|
|
|
|
|
|
{ |
236
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
237
|
0
|
0
|
|
|
|
|
if ( !defined $self->{ database }->{ connection } ) |
238
|
|
|
|
|
|
|
{ |
239
|
0
|
|
|
|
|
|
$log->error( "Tentando reverter uma transação sem uma conexão com DB..." ); |
240
|
0
|
|
|
|
|
|
return FALSE; |
241
|
|
|
|
|
|
|
} |
242
|
0
|
0
|
|
|
|
|
my $rc = $self->{ database }->{ connection }->rollback or die $self->{ database }->{ connection }->errstr; |
243
|
0
|
|
|
|
|
|
return $rc; |
244
|
|
|
|
|
|
|
} ## end sub rollback |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 C<prepareQuery()> |
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub prepareQuery |
250
|
|
|
|
|
|
|
{ |
251
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
252
|
0
|
|
|
|
|
|
my $sql = $parameters{ sql }; |
253
|
|
|
|
|
|
|
|
254
|
0
|
0
|
|
|
|
|
my $sth = $self->{ database }->{ connection }->prepare( $sql ) or die $self->{ database }->{ connection }->errstr; |
255
|
0
|
|
|
|
|
|
return $sth; |
256
|
|
|
|
|
|
|
} ## end sub prepareQuery |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 C<doQuery()> |
259
|
|
|
|
|
|
|
=cut |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub doQuery |
262
|
|
|
|
|
|
|
{ |
263
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
264
|
0
|
|
|
|
|
|
my $sql = $parameters{ sql }; |
265
|
|
|
|
|
|
|
|
266
|
0
|
0
|
|
|
|
|
my $sth = $self->{ database }->{ connection }->do( $sql ) or die $self->{ database }->{ connection }->errstr; |
267
|
0
|
|
|
|
|
|
return $sth; |
268
|
|
|
|
|
|
|
} ## end sub doQuery |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 C<executeQuery()> |
271
|
|
|
|
|
|
|
=cut |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub executeQuery() |
274
|
|
|
|
|
|
|
{ |
275
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
276
|
0
|
|
|
|
|
|
my $sql = $parameters{ sql }; |
277
|
|
|
|
|
|
|
|
278
|
0
|
0
|
|
|
|
|
$self->connectDB() unless ( defined( $self->{ database }->{ connection } ) ); |
279
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $sth = $self->prepareQuery( sql => $sql ); |
281
|
0
|
0
|
|
|
|
|
my $res = $sth->execute() or die $self->{ database }->{ connection }->errstr; |
282
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
my @rows; |
284
|
|
|
|
|
|
|
my $line; |
285
|
0
|
|
|
|
|
|
push( @rows, $line ) while ( $line = $sth->fetchrow_hashref ); |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
return @rows; |
288
|
|
|
|
|
|
|
} ## end sub executeQuery |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head2 C<teste()> |
291
|
|
|
|
|
|
|
=cut |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub teste() |
294
|
|
|
|
|
|
|
{ |
295
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
$self->{ configurations }->{ teste } = 'LALA'; |
298
|
0
|
|
|
|
|
|
return $self; |
299
|
|
|
|
|
|
|
} ## end sub teste |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 C<getFileMD5()> |
302
|
|
|
|
|
|
|
------------------------------------------------------------------------------- |
303
|
|
|
|
|
|
|
Retorna o MD5 do arquivo |
304
|
|
|
|
|
|
|
Parametro 1 - Caminho e nome do arquivo a ser calculado |
305
|
|
|
|
|
|
|
Retorna o MD5 do arquivo informado |
306
|
|
|
|
|
|
|
------------------------------------------------------------------------------- |
307
|
|
|
|
|
|
|
=cut |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub getFileMD5() |
310
|
|
|
|
|
|
|
{ |
311
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
312
|
0
|
|
|
|
|
|
my $file = $parameters{ file }; |
313
|
|
|
|
|
|
|
|
314
|
0
|
0
|
|
|
|
|
return FALSE unless ( -e $file ); |
315
|
|
|
|
|
|
|
|
316
|
0
|
|
|
|
|
|
my $return; |
317
|
|
|
|
|
|
|
|
318
|
0
|
|
|
|
|
|
eval { require Digest::MD5; }; |
|
0
|
|
|
|
|
|
|
319
|
0
|
0
|
|
|
|
|
if ( $@ ) |
320
|
|
|
|
|
|
|
{ |
321
|
0
|
|
|
|
|
|
$log->error( 'Package Digest::MD5 não encontrado...' ); |
322
|
0
|
|
|
|
|
|
return FALSE; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
0
|
0
|
|
|
|
|
if ( open( my $fh, $file ) ) |
326
|
|
|
|
|
|
|
{ |
327
|
0
|
|
|
|
|
|
binmode( $fh ); |
328
|
0
|
|
|
|
|
|
$return = Digest::MD5->new->addfile( $fh )->hexdigest; |
329
|
0
|
|
|
|
|
|
close( $fh ); |
330
|
|
|
|
|
|
|
} ## end if ( open( my $fh, $file...)) |
331
|
|
|
|
|
|
|
else |
332
|
|
|
|
|
|
|
{ |
333
|
0
|
|
|
|
|
|
$log->error( "Não foi possÃvel abrir o arquivo [ $file ]..." ); |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
0
|
|
|
|
|
|
return $return; |
337
|
|
|
|
|
|
|
} ## end sub getFileMD5 |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head2 C<parseBlockText()> |
340
|
|
|
|
|
|
|
=cut |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub parseBlockText() |
343
|
|
|
|
|
|
|
{ |
344
|
0
|
|
|
0
|
1
|
|
my $me = ( caller( 0 ) )[ 3 ]; |
345
|
0
|
|
|
|
|
|
my $parent = ( caller( 1 ) )[ 3 ]; |
346
|
0
|
|
|
|
|
|
$log->debug( "parseBlockText", { package => __PACKAGE__, file => __FILE__, me => $me, parent => $parent } ); |
347
|
|
|
|
|
|
|
|
348
|
0
|
|
|
|
|
|
my ( $self, %parameters ) = @_; |
349
|
0
|
|
|
|
|
|
my $file = $parameters{ file }; |
350
|
0
|
|
|
|
|
|
my $layout = $parameters{ layout }; |
351
|
0
|
|
|
|
|
|
my $length_type = $parameters{ length_type }; |
352
|
0
|
|
|
|
|
|
my $retorno = { rows => undef, error => 0, message => undef, }; |
353
|
|
|
|
|
|
|
|
354
|
0
|
0
|
0
|
|
|
|
if ( !$file || !-e $file ) |
355
|
|
|
|
|
|
|
{ |
356
|
0
|
|
|
|
|
|
$log->error( "O arquivo [ $file ] não existe..." ); |
357
|
0
|
|
|
|
|
|
$retorno->{ message } = 'Arquivo não existe'; |
358
|
0
|
|
|
|
|
|
$retorno->{ error } = TRUE; |
359
|
0
|
|
|
|
|
|
return $retorno; |
360
|
|
|
|
|
|
|
} ## end if ( !$file || !-e $file...) |
361
|
|
|
|
|
|
|
|
362
|
0
|
|
|
|
|
|
my $fh; |
363
|
0
|
|
|
|
|
|
my $types = MIME::Types->new; |
364
|
0
|
|
|
|
|
|
my $mime = $types->mimeTypeOf( $file ); |
365
|
|
|
|
|
|
|
|
366
|
0
|
0
|
|
|
|
|
if ( $mime->{ MT_type } =~ /application\/zip/ ) |
367
|
|
|
|
|
|
|
{ |
368
|
0
|
|
|
|
|
|
$log->info( "Arquivo zipado, tentando descompactar..." ); |
369
|
0
|
0
|
|
|
|
|
$fh = new IO::Uncompress::Unzip $file or die "IO::Uncompress::Unzip failed: $UnzipError\n"; |
370
|
0
|
|
|
|
|
|
$log->info( "Arquivo descompactado com sucesso..." ); |
371
|
|
|
|
|
|
|
|
372
|
0
|
|
|
|
|
|
my $HeaderInfo = $fh->getHeaderInfo(); |
373
|
0
|
|
|
|
|
|
my $UncompressedLength = $HeaderInfo->{ UncompressedLength }->get64bit(); |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
} ## end if ( $mime->{ MT_type ...}) |
376
|
|
|
|
|
|
|
else |
377
|
|
|
|
|
|
|
{ |
378
|
0
|
0
|
|
|
|
|
open $fh, "<:encoding(UTF-8)", $file or die "Erro ao abrir o arquivo [ $file ]...\n"; |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
|
381
|
0
|
|
|
|
|
|
$log->info( "Começando a parsear o arquivo [ $file ]..." ); |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
while ( my $linha = <$fh> ) |
384
|
|
|
|
|
|
|
{ |
385
|
0
|
|
|
|
|
|
$linha =~ s/\n|\r//g; |
386
|
|
|
|
|
|
|
|
387
|
0
|
|
|
|
|
|
my $tipo_de_registro = substr( $linha, 0, $length_type ); |
388
|
0
|
|
|
|
|
|
my $posicao = 0; |
389
|
0
|
|
|
|
|
|
my $auxiliar = (); |
390
|
|
|
|
|
|
|
|
391
|
0
|
0
|
|
|
|
|
if ( !$layout->{ $tipo_de_registro } ) |
392
|
|
|
|
|
|
|
{ |
393
|
0
|
|
|
|
|
|
my $tipos = join ",", sort keys %{ $layout }; |
|
0
|
|
|
|
|
|
|
394
|
0
|
|
|
|
|
|
my $msg = "Não existe o tipo de registro [ $tipo_de_registro ] no layout cadastrado [ $tipos ] na linha [ $. ]..."; |
395
|
0
|
|
|
|
|
|
$log->error( $msg ); |
396
|
0
|
|
|
|
|
|
$log->error( "Linha [ $. ] = [$linha]..." ); |
397
|
0
|
|
|
|
|
|
$retorno->{ rows } = undef; |
398
|
0
|
|
|
|
|
|
$retorno->{ message } = $msg; |
399
|
0
|
|
|
|
|
|
$retorno->{ error } = 1; |
400
|
0
|
|
|
|
|
|
return $retorno; |
401
|
|
|
|
|
|
|
} ## end if ( !$layout->{ $tipo_de_registro...}) |
402
|
|
|
|
|
|
|
|
403
|
0
|
|
|
|
|
|
my $tamanho_da_linha_no_layout = $layout->{ $tipo_de_registro }->{ total_length }; |
404
|
0
|
|
|
|
|
|
my $tamanho_da_linha_no_arquivo = length( $linha ); |
405
|
|
|
|
|
|
|
|
406
|
0
|
0
|
|
|
|
|
if ( $tamanho_da_linha_no_arquivo != $tamanho_da_linha_no_layout ) |
407
|
|
|
|
|
|
|
{ |
408
|
0
|
|
|
|
|
|
my $msg = "Tamanho da linha [ $. ] do tipo [ $tipo_de_registro ] no arquivo [ $file ] ($tamanho_da_linha_no_arquivo) esta diferente do layout ($tamanho_da_linha_no_layout)"; |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
#my $msg = "Tamanho da linha [ %d ] do tipo [ %s ] no arquivo [ %s ] ( %d ) esta diferente do layout ( %d )"; |
411
|
|
|
|
|
|
|
#$log->error( $msg ); |
412
|
0
|
|
|
|
|
|
$retorno->{ rows } = undef; |
413
|
0
|
|
|
|
|
|
$retorno->{ message } = $msg; |
414
|
0
|
|
|
|
|
|
$retorno->{ error } = 1; |
415
|
0
|
|
|
|
|
|
return $retorno; |
416
|
|
|
|
|
|
|
} ## end if ( $tamanho_da_linha_no_arquivo...) |
417
|
|
|
|
|
|
|
|
418
|
0
|
|
|
|
|
|
foreach my $field ( @{ $layout->{ $tipo_de_registro }->{ fields } } ) |
|
0
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
{ |
420
|
0
|
|
|
|
|
|
$auxiliar->{ $field->{ field } } = $self->trim( substr( $linha, $posicao, $field->{ length } ) ); |
421
|
0
|
|
|
|
|
|
$posicao += $field->{ length }; |
422
|
|
|
|
|
|
|
|
423
|
0
|
|
|
|
|
|
my $out = $field->{ out }; |
424
|
|
|
|
|
|
|
|
425
|
0
|
0
|
0
|
|
|
|
if ( $field->{ match } ) |
|
|
0
|
|
|
|
|
|
426
|
|
|
|
|
|
|
{ |
427
|
0
|
0
|
|
|
|
|
if ( $auxiliar->{ $field->{ field } } !~ /$field->{match}/ ) |
428
|
|
|
|
|
|
|
{ |
429
|
0
|
|
|
|
|
|
my $msg = "O campo [ $field->{ field } ] com o valor [ $auxiliar->{ $field->{ field } } ] não corresponde a regra de validação [ $field->{match} ] no registro [ $. ]..."; |
430
|
0
|
|
|
|
|
|
$log->error( $msg ); |
431
|
0
|
|
|
|
|
|
$retorno->{ rows } = undef; |
432
|
0
|
|
|
|
|
|
$retorno->{ message } = $msg; |
433
|
0
|
|
|
|
|
|
$retorno->{ error } = 1; |
434
|
0
|
|
|
|
|
|
return $retorno; |
435
|
|
|
|
|
|
|
} ## end if ( $auxiliar->{ $field...}) |
436
|
|
|
|
|
|
|
|
437
|
0
|
0
|
|
|
|
|
if ( $out ) |
438
|
|
|
|
|
|
|
{ |
439
|
0
|
|
|
|
|
|
$out =~ s/\?\?\?/$auxiliar->{ $field->{field} }/g; |
440
|
0
|
|
|
|
|
|
$auxiliar->{ $field->{ field } } = eval( $out ); |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
} ## end if ( $field->{ match }...) |
443
|
|
|
|
|
|
|
elsif ( $out && $out !~ /\$/ ) |
444
|
|
|
|
|
|
|
{ |
445
|
0
|
|
|
|
|
|
$out =~ s/\?\?\?/$auxiliar->{ $field->{field} }/g; |
446
|
0
|
|
|
|
|
|
$auxiliar->{ $field->{ field } } = eval( $out ); |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
} ## end foreach my $field ( @{ $layout...}) |
449
|
|
|
|
|
|
|
|
450
|
0
|
|
|
|
|
|
push( @{ $retorno->{ rows }->{ $tipo_de_registro } }, $auxiliar ); |
|
0
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
} ## end while ( my $linha = <$fh>...) |
452
|
0
|
|
|
|
|
|
return $retorno; |
453
|
|
|
|
|
|
|
} ## end sub parseBlockText |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
=head2 C<parseCSV()> |
456
|
|
|
|
|
|
|
=cut |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub parseCSV() |
459
|
|
|
|
|
|
|
{ |
460
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
461
|
0
|
|
|
|
|
|
my $file = $parameters{ file }; |
462
|
0
|
|
0
|
|
|
|
my $sep_char = $parameters{ sep_char } // ','; |
463
|
0
|
|
0
|
|
|
|
my $quote_char = $parameters{ quote_char } // '"'; |
464
|
0
|
|
0
|
|
|
|
my $encoding = $parameters{ encoding } // 'iso-8859-1'; |
465
|
0
|
|
|
|
|
|
my $originalHeader = $parameters{ originalHeader }; |
466
|
0
|
|
|
|
|
|
my $retorno = { rows => undef, error => 0, message => undef, }; |
467
|
|
|
|
|
|
|
|
468
|
0
|
|
|
|
|
|
$log->info( "Começando a parsear o arquivo [ $file ]..." ); |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
# Read/parse CSV |
471
|
0
|
|
|
|
|
|
eval { require Text::CSV_XS; }; |
|
0
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
|
473
|
0
|
0
|
|
|
|
|
if ( $@ ) |
474
|
|
|
|
|
|
|
{ |
475
|
0
|
|
|
|
|
|
$log->error( $@ ); |
476
|
0
|
|
|
|
|
|
return $retorno; |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
0
|
|
|
|
|
|
my $csv = eval { |
480
|
|
|
|
|
|
|
|
481
|
0
|
|
|
|
|
|
Text::CSV_XS->new( |
482
|
|
|
|
|
|
|
{ |
483
|
|
|
|
|
|
|
binary => 1, |
484
|
|
|
|
|
|
|
auto_diag => 0, |
485
|
|
|
|
|
|
|
diag_verbose => 0, |
486
|
|
|
|
|
|
|
blank_is_undef => 1, |
487
|
|
|
|
|
|
|
empty_is_undef => 1, |
488
|
|
|
|
|
|
|
allow_loose_quotes => 0, |
489
|
|
|
|
|
|
|
sep_char => $sep_char, |
490
|
|
|
|
|
|
|
quote_char => $quote_char, |
491
|
|
|
|
|
|
|
strict => 1, |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
); |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
}; |
496
|
|
|
|
|
|
|
|
497
|
0
|
0
|
|
|
|
|
if ( $@ ) |
498
|
|
|
|
|
|
|
{ |
499
|
0
|
|
|
|
|
|
$log->error( $@ ); |
500
|
0
|
|
|
|
|
|
$retorno->{ error } = 1; |
501
|
0
|
|
|
|
|
|
$retorno->{ message } = $@; |
502
|
|
|
|
|
|
|
} ## end if ( $@ ) |
503
|
|
|
|
|
|
|
else |
504
|
|
|
|
|
|
|
{ |
505
|
|
|
|
|
|
|
$csv->callbacks( |
506
|
|
|
|
|
|
|
after_parse => sub { |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
# Limpar os espaços em branco no começo e no final de cada campo. |
509
|
0
|
0
|
|
0
|
|
|
map { defined $_ ? ( ( $_ =~ /^\s+$/ ) ? ( $_ = undef ) : ( s/^\s+|\s+$//g ) ) : undef } @{ $_[ 1 ] }; |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
}, |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
#error => sub { |
513
|
|
|
|
|
|
|
# my ( $err, $msg, $pos, $recno, $fldno ) = @_; |
514
|
|
|
|
|
|
|
# Text::CSV_XS->SetDiag(0); |
515
|
|
|
|
|
|
|
# return; |
516
|
|
|
|
|
|
|
#} |
517
|
0
|
|
|
|
|
|
); |
518
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
my @rows; |
520
|
|
|
|
|
|
|
my $fh; |
521
|
0
|
|
|
|
|
|
my $types = MIME::Types->new; |
522
|
0
|
|
|
|
|
|
my $mime = $types->mimeTypeOf( $file ); |
523
|
|
|
|
|
|
|
|
524
|
0
|
0
|
|
|
|
|
if ( $mime->{ MT_type } =~ /application\/zip/ ) |
525
|
|
|
|
|
|
|
{ |
526
|
0
|
|
|
|
|
|
$log->info( "Arquivo zipado, tentando descompactar..." ); |
527
|
0
|
0
|
|
|
|
|
$fh = new IO::Uncompress::Unzip $file or die "IO::Uncompress::Unzip failed: $UnzipError\n"; |
528
|
0
|
|
|
|
|
|
$log->info( "Arquivo descompactado com sucesso..." ); |
529
|
|
|
|
|
|
|
|
530
|
0
|
|
|
|
|
|
my $HeaderInfo = $fh->getHeaderInfo(); |
531
|
0
|
|
|
|
|
|
my $UncompressedLength = $HeaderInfo->{ UncompressedLength }->get64bit(); |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
} ## end if ( $mime->{ MT_type ...}) |
534
|
|
|
|
|
|
|
else |
535
|
|
|
|
|
|
|
{ |
536
|
0
|
0
|
|
|
|
|
open $fh, "<:encoding($encoding)", $file or die "Erro ao abrir o arquivo [ $file ]...\n"; |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
|
539
|
0
|
|
|
|
|
|
my @header = eval { |
540
|
|
|
|
|
|
|
$csv->header( |
541
|
|
|
|
|
|
|
$fh, |
542
|
|
|
|
|
|
|
{ |
543
|
|
|
|
|
|
|
detect_bom => ( $encoding =~ /utf-8/i ) ? 1 : 0, |
544
|
|
|
|
|
|
|
sep_set => [ $sep_char ], |
545
|
|
|
|
|
|
|
munge_column_names => sub { |
546
|
0
|
|
|
0
|
|
|
uc; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
} |
549
|
0
|
0
|
|
|
|
|
); |
550
|
|
|
|
|
|
|
}; |
551
|
|
|
|
|
|
|
|
552
|
0
|
|
|
|
|
|
my ( $errorCode, $errorMessage, $position, $line, $field ) = $csv->error_diag(); |
553
|
0
|
0
|
|
|
|
|
if ( $errorCode > 0 ) |
554
|
|
|
|
|
|
|
{ |
555
|
0
|
|
|
|
|
|
undef @rows; |
556
|
0
|
|
|
|
|
|
$retorno->{ error } = $errorCode; |
557
|
0
|
|
|
|
|
|
$retorno->{ message } = "$errorMessage @ linha $line, posição $position, campo $field"; |
558
|
0
|
|
|
|
|
|
return $retorno; |
559
|
|
|
|
|
|
|
} ## end if ( $errorCode > 0 ) |
560
|
0
|
|
|
|
|
|
$retorno->{ header } = \@header; |
561
|
|
|
|
|
|
|
|
562
|
0
|
0
|
|
|
|
|
if ( $originalHeader ) |
563
|
|
|
|
|
|
|
{ |
564
|
0
|
0
|
|
|
|
|
if ( !$self->validaHeader( originalHeader => $originalHeader, header => \@header ) ) |
565
|
|
|
|
|
|
|
{ |
566
|
0
|
|
|
|
|
|
my $msg = 'Header do arquivo está diferente do layout...'; |
567
|
0
|
|
|
|
|
|
$retorno->{ error } = 1; |
568
|
0
|
|
|
|
|
|
$retorno->{ message } = $msg; |
569
|
0
|
|
|
|
|
|
return $retorno; |
570
|
|
|
|
|
|
|
} ## end if ( !$self->validaHeader...) |
571
|
|
|
|
|
|
|
else |
572
|
|
|
|
|
|
|
{ |
573
|
0
|
|
|
|
|
|
$log->info( "*** Header validado com sucesso ***" ); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
} ## end if ( $originalHeader ) |
576
|
|
|
|
|
|
|
|
577
|
0
|
|
|
|
|
|
while ( my $row = $csv->getline( $fh ) ) |
578
|
|
|
|
|
|
|
{ |
579
|
0
|
|
|
|
|
|
push @rows, $row; |
580
|
|
|
|
|
|
|
} |
581
|
0
|
|
|
|
|
|
close $fh; |
582
|
|
|
|
|
|
|
|
583
|
0
|
|
|
|
|
|
( $errorCode, $errorMessage, $position, $line, $field ) = $csv->error_diag(); |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
# 2012 "EOF - End of data in parsing input stream" |
586
|
|
|
|
|
|
|
# 2014 "ENF - Inconsistent number of fields" |
587
|
|
|
|
|
|
|
# 2023 "EIQ - QUO character not allowed" |
588
|
|
|
|
|
|
|
# 2027 "EIQ - Quoted field not terminated" |
589
|
0
|
0
|
0
|
|
|
|
if ( $errorCode > 0 && $errorCode != 2012 ) |
590
|
|
|
|
|
|
|
{ |
591
|
0
|
|
|
|
|
|
undef @rows; |
592
|
0
|
0
|
|
|
|
|
if ( $errorMessage =~ /Inconsistent number of fields/i ) |
593
|
|
|
|
|
|
|
{ |
594
|
0
|
|
|
|
|
|
$errorMessage = 'Número inconsistente de campos'; |
595
|
|
|
|
|
|
|
} |
596
|
0
|
|
|
|
|
|
$retorno->{ error } = $errorCode; |
597
|
0
|
|
|
|
|
|
$retorno->{ message } = "$errorMessage @ linha $line, posição $position, campo $field"; |
598
|
|
|
|
|
|
|
} ## end if ( $errorCode > 0 &&...) |
599
|
|
|
|
|
|
|
else |
600
|
|
|
|
|
|
|
{ |
601
|
0
|
|
|
|
|
|
@{ $retorno->{ rows } } = @rows; |
|
0
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
} |
603
|
|
|
|
|
|
|
} ## end else [ if ( $@ ) ] |
604
|
|
|
|
|
|
|
|
605
|
0
|
|
|
|
|
|
return $retorno; |
606
|
|
|
|
|
|
|
} ## end sub parseCSV |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=head2 C<validaHeader()> |
609
|
|
|
|
|
|
|
=cut |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
sub validaHeader() |
612
|
|
|
|
|
|
|
{ |
613
|
0
|
|
|
0
|
1
|
|
$log->debug( "validaHeader", { package => __PACKAGE__ } ); |
614
|
0
|
|
|
|
|
|
my ( $self, %parameters ) = @_; |
615
|
0
|
|
|
|
|
|
my @originalHeader = @{ $parameters{ originalHeader } }; |
|
0
|
|
|
|
|
|
|
616
|
0
|
|
|
|
|
|
my @header = @{ $parameters{ header } }; |
|
0
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
|
618
|
0
|
|
|
|
|
|
$log->info( "Validando o header do arquivo..." ); |
619
|
|
|
|
|
|
|
|
620
|
0
|
|
|
|
|
|
my $originalHeaderString = join( '_&_', @originalHeader ); |
621
|
0
|
|
|
|
|
|
my $headerString = join( '_&_', @header ); |
622
|
|
|
|
|
|
|
|
623
|
0
|
0
|
|
|
|
|
return ( $originalHeaderString eq $headerString ) ? TRUE : FALSE; |
624
|
|
|
|
|
|
|
} ## end sub validaHeader |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=head2 C<validaArCorreios()> |
627
|
|
|
|
|
|
|
=cut |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
sub validaArCorreios() |
630
|
|
|
|
|
|
|
{ |
631
|
|
|
|
|
|
|
#$log->debug( "validaArCorreios", { package => __PACKAGE__ } ); |
632
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
633
|
0
|
|
|
|
|
|
my $arCorreios = $parameters{ ar }; |
634
|
|
|
|
|
|
|
|
635
|
0
|
0
|
|
|
|
|
return ( $arCorreios =~ /^([a-zA-Z]{2})(\d{9})([a-zA-Z]{2})$/ ) ? TRUE : FALSE; |
636
|
|
|
|
|
|
|
} ## end sub validaArCorreios |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
=head2 C<trim()> |
639
|
|
|
|
|
|
|
=cut |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub trim() |
642
|
|
|
|
|
|
|
{ |
643
|
0
|
|
|
0
|
1
|
|
my ( $self, $string ) = @_; |
644
|
|
|
|
|
|
|
|
645
|
0
|
|
|
|
|
|
eval { $string =~ s/^\s+|\s+$//g; }; |
|
0
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
|
647
|
0
|
0
|
|
|
|
|
if ( $@ ) |
648
|
|
|
|
|
|
|
{ |
649
|
0
|
|
|
|
|
|
$log->error( "Erro ao fazer o trim na string $string" ); |
650
|
|
|
|
|
|
|
} |
651
|
|
|
|
|
|
|
|
652
|
0
|
|
|
|
|
|
return $string; |
653
|
|
|
|
|
|
|
} ## end sub trim |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
=head2 C<getProgressBar()> |
656
|
|
|
|
|
|
|
=cut |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
sub getProgressBar() |
659
|
|
|
|
|
|
|
{ |
660
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
661
|
0
|
|
0
|
|
|
|
my $name = $parameters{ name } // 'Progress'; |
662
|
0
|
|
0
|
|
|
|
my $count = $parameters{ count } // 0; |
663
|
0
|
|
0
|
|
|
|
my $remove = $parameters{ remove } // 1; |
664
|
0
|
|
0
|
|
|
|
my $eta = $parameters{ eta } // 'linear'; |
665
|
0
|
|
0
|
|
|
|
my $silent = $parameters{ silent } // !DEBUG; |
666
|
|
|
|
|
|
|
|
667
|
0
|
|
|
|
|
|
eval { require Term::ProgressBar; }; |
|
0
|
|
|
|
|
|
|
668
|
0
|
0
|
|
|
|
|
if ( $@ ) |
669
|
|
|
|
|
|
|
{ |
670
|
0
|
|
|
|
|
|
die Dumper 'Sem o Term::ProgressBar...'; |
671
|
|
|
|
|
|
|
} |
672
|
|
|
|
|
|
|
|
673
|
0
|
|
|
|
|
|
my $progress = Term::ProgressBar->new( |
674
|
|
|
|
|
|
|
{ |
675
|
|
|
|
|
|
|
name => $name, |
676
|
|
|
|
|
|
|
count => $count, |
677
|
|
|
|
|
|
|
remove => $remove, |
678
|
|
|
|
|
|
|
ETA => $eta, |
679
|
|
|
|
|
|
|
silent => $silent, |
680
|
|
|
|
|
|
|
} |
681
|
|
|
|
|
|
|
); |
682
|
|
|
|
|
|
|
|
683
|
0
|
|
|
|
|
|
return $progress; |
684
|
|
|
|
|
|
|
} ## end sub getProgressBar |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=head2 C<getTimeStampHash()> |
687
|
|
|
|
|
|
|
=cut |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
690
|
|
|
|
|
|
|
# Retorna o timestamp atual do sistema em forma de HASH |
691
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
692
|
|
|
|
|
|
|
sub getTimeStampHash |
693
|
|
|
|
|
|
|
{ |
694
|
0
|
|
|
0
|
1
|
|
my ( $self, %parameters ) = @_; |
695
|
0
|
|
|
|
|
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( time ); |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
{ |
698
|
0
|
|
|
|
|
|
year => $year + 1900, |
699
|
|
|
|
|
|
|
month => sprintf( '%02d', ( $mon + 1 ) ), |
700
|
|
|
|
|
|
|
day => sprintf( '%02d', $mday ), |
701
|
|
|
|
|
|
|
hour => sprintf( '%02d', $hour ), |
702
|
|
|
|
|
|
|
min => sprintf( '%02d', $min ), |
703
|
|
|
|
|
|
|
sec => sprintf( '%02d', $sec ), |
704
|
|
|
|
|
|
|
wday => $wday, |
705
|
|
|
|
|
|
|
yday => $yday, |
706
|
|
|
|
|
|
|
isdst => $isdst |
707
|
|
|
|
|
|
|
}; |
708
|
|
|
|
|
|
|
} ## end sub getTimeStampHash |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=head2 C<getTimeStamp()> |
711
|
|
|
|
|
|
|
=cut |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
714
|
|
|
|
|
|
|
# Retorna o timestamp atual do sistema |
715
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
716
|
|
|
|
|
|
|
sub getTimeStamp |
717
|
|
|
|
|
|
|
{ |
718
|
0
|
|
|
0
|
1
|
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( time ); |
719
|
0
|
|
|
|
|
|
return sprintf( "%4d%02d%02d%02d%02d%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec ); |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
723
|
|
|
|
|
|
|
## Below is the stub of documentation for your module. |
724
|
|
|
|
|
|
|
## You better edit it! |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
=encoding UTF-8 |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=head1 NAME |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
Siffra::Tools - Module abstract (<= 44 characters) goes here |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=head1 SYNOPSIS |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
use Siffra::Tools; |
736
|
|
|
|
|
|
|
blah blah blah |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
=head1 DESCRIPTION |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
Stub documentation for this module was created by ExtUtils::ModuleMaker. |
742
|
|
|
|
|
|
|
It looks like the author of the extension was negligent enough |
743
|
|
|
|
|
|
|
to leave the stub unedited. |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
Blah blah blah. |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
=head1 USAGE |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
=head1 BUGS |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
=head1 SUPPORT |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=head1 AUTHOR |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
Luiz Benevenuto |
763
|
|
|
|
|
|
|
CPAN ID: LUIZBENE |
764
|
|
|
|
|
|
|
Siffra TI |
765
|
|
|
|
|
|
|
luiz@siffra.com.br |
766
|
|
|
|
|
|
|
https://siffra.com.br |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=head1 COPYRIGHT |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
This program is free software; you can redistribute |
771
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
The full text of the license can be found in the |
774
|
|
|
|
|
|
|
LICENSE file included with this module. |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
=head1 SEE ALSO |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
perl(1). |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
=cut |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
1; |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
788
|
|
|
|
|
|
|
|