line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Test::DWG::LibreDWG::DwgRead; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
74542
|
use strict; |
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
115
|
|
4
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
112
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2241
|
use Capture::Tiny qw(capture); |
|
4
|
|
|
|
|
123084
|
|
|
4
|
|
|
|
|
247
|
|
7
|
4
|
|
|
4
|
|
1984
|
use File::Copy; |
|
4
|
|
|
|
|
9535
|
|
|
4
|
|
|
|
|
225
|
|
8
|
4
|
|
|
4
|
|
2158
|
use File::Find::Rule; |
|
4
|
|
|
|
|
34480
|
|
|
4
|
|
|
|
|
31
|
|
9
|
4
|
|
|
4
|
|
2100
|
use File::Find::Rule::DWG; |
|
4
|
|
|
|
|
117203
|
|
|
4
|
|
|
|
|
41
|
|
10
|
4
|
|
|
4
|
|
222
|
use File::Path qw(mkpath); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
239
|
|
11
|
4
|
|
|
4
|
|
1887
|
use File::Spec::Functions qw(catfile); |
|
4
|
|
|
|
|
3459
|
|
|
4
|
|
|
|
|
303
|
|
12
|
4
|
|
|
4
|
|
29
|
use File::Temp qw(tempdir); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
218
|
|
13
|
4
|
|
|
4
|
|
8159
|
use Getopt::Std; |
|
4
|
|
|
|
|
197
|
|
|
4
|
|
|
|
|
236
|
|
14
|
4
|
|
|
4
|
|
1861
|
use IO::Barf qw(barf); |
|
4
|
|
|
|
|
2336
|
|
|
4
|
|
|
|
|
60
|
|
15
|
4
|
|
|
4
|
|
209
|
use Readonly; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
3543
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar our $DR => 'dwgread'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.03; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Constructor. |
22
|
|
|
|
|
|
|
sub new { |
23
|
2
|
|
|
2
|
1
|
1690
|
my ($class, @params) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Create object. |
26
|
2
|
|
|
|
|
7
|
my $self = bless {}, $class; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Object. |
29
|
2
|
|
|
|
|
8
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Run. |
33
|
|
|
|
|
|
|
sub run { |
34
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Process arguments. |
37
|
1
|
|
|
|
|
11
|
$self->{'_opts'} = { |
38
|
|
|
|
|
|
|
'd' => undef, |
39
|
|
|
|
|
|
|
'h' => 0, |
40
|
|
|
|
|
|
|
'i' => 0, |
41
|
|
|
|
|
|
|
'm' => undef, |
42
|
|
|
|
|
|
|
'v' => 1, |
43
|
|
|
|
|
|
|
}; |
44
|
1
|
50
|
33
|
|
|
7
|
if (! getopts('d:him:v:', $self->{'_opts'}) || @ARGV < 1 |
|
|
|
33
|
|
|
|
|
45
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'}) { |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
162
|
print STDERR "Usage: $0 [-d test_dir] [-h] [-i] [-m match_string] [-v level] [--version] directory\n"; |
48
|
1
|
|
|
|
|
16
|
print STDERR "\t-d test_dir\tTest directory (default is directory in system tmp).\n"; |
49
|
1
|
|
|
|
|
13
|
print STDERR "\t-h\t\tPrint help.\n"; |
50
|
1
|
|
|
|
|
12
|
print STDERR "\t-i\t\tIgnore errors.\n"; |
51
|
1
|
|
|
|
|
11
|
print STDERR "\t-m match_string\tMatch string (default is not defined).\n"; |
52
|
1
|
|
|
|
|
11
|
print STDERR "\t-v level\tVerbosity level (default 1, min 0, max 9).\n"; |
53
|
1
|
|
|
|
|
11
|
print STDERR "\t--version\tPrint version.\n"; |
54
|
1
|
|
|
|
|
12
|
print STDERR "\tdirectory\tDirectory with DWG files to test.\n"; |
55
|
1
|
|
|
|
|
21
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
$self->{'_directory'} = shift @ARGV; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'v'} == 0) { |
60
|
0
|
|
|
|
|
|
warn "Verbosity level 0 hasn't detection of ERRORs.\n"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $tmp_dir = $self->{'_opts'}->{'d'}; |
64
|
0
|
0
|
0
|
|
|
|
if (defined $tmp_dir && ! -d $tmp_dir) { |
65
|
0
|
|
|
|
|
|
mkpath($tmp_dir); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
0
|
|
|
|
if (! defined $tmp_dir || ! -d $tmp_dir) { |
68
|
0
|
|
|
|
|
|
$tmp_dir = tempdir(CLEANUP => 1); |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$self->{'_tmp_dir'} = $tmp_dir; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Verbose level. |
73
|
0
|
|
|
|
|
|
my $v = '-v'.$self->{'_opts'}->{'v'}; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $file_num = 1; |
76
|
0
|
|
|
|
|
|
foreach my $dwg_file_in (File::Find::Rule->dwg->in($self->{'_directory'})) { |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Copy DWG file to dir. |
79
|
0
|
|
|
|
|
|
my $dwg_file_out = catfile($tmp_dir, $file_num.'.dwg'); |
80
|
0
|
|
|
|
|
|
copy($dwg_file_in, $dwg_file_out); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# dwgread. |
83
|
0
|
|
|
|
|
|
my $dwgread = "$DR $v $dwg_file_out"; |
84
|
0
|
|
|
|
|
|
$self->_exec($dwgread, $file_num.'-dwgread', $dwg_file_in); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$file_num++; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _exec { |
93
|
0
|
|
|
0
|
|
|
my ($self, $command, $log_prefix, $dwg_file) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my ($stdout, $stderr, $exit_code) = capture { |
96
|
0
|
|
|
0
|
|
|
system($command); |
97
|
0
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ($exit_code) { |
100
|
0
|
|
|
|
|
|
print STDERR "Cannot dwgread '$dwg_file'.\n"; |
101
|
0
|
|
|
|
|
|
print STDERR "\tCommand '$command' exit with $exit_code.\n"; |
102
|
0
|
|
|
|
|
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ($stdout) { |
106
|
0
|
|
|
|
|
|
my $stdout_file = catfile($self->{'_tmp_dir'}, |
107
|
|
|
|
|
|
|
$log_prefix.'-stdout.log'); |
108
|
0
|
|
|
|
|
|
barf($stdout_file, $stdout); |
109
|
|
|
|
|
|
|
} |
110
|
0
|
0
|
|
|
|
|
if ($stderr) { |
111
|
0
|
|
|
|
|
|
my $stderr_file = catfile($self->{'_tmp_dir'}, |
112
|
|
|
|
|
|
|
$log_prefix.'-stderr.log'); |
113
|
0
|
|
|
|
|
|
barf($stderr_file, $stderr); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Report errors. |
116
|
0
|
0
|
|
|
|
|
if (! $self->{'_opts'}->{'i'}) { |
117
|
0
|
0
|
|
|
|
|
if (my @num = ($stderr =~ m/ERROR/gms)) { |
118
|
0
|
|
|
|
|
|
print STDERR "dwgread '$dwg_file' has ".scalar @num." ERRORs\n"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if (defined $self->{'_opts'}->{'m'}) { |
123
|
0
|
|
|
|
|
|
foreach my $match_line ($self->_match_lines($stderr)) { |
124
|
0
|
|
|
|
|
|
print $match_line."\n"; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _match_lines { |
133
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my @ret; |
136
|
0
|
|
|
|
|
|
foreach my $line (split m/\n/ms, $string) { |
137
|
0
|
0
|
|
|
|
|
if ($line =~ /$self->{'_opts'}->{'m'}/) { |
138
|
0
|
|
|
|
|
|
push @ret, $line; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return @ret; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |