| 1 | package App::Test::DWG::LibreDWG::DwgRead; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Capture::Tiny qw(capture); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Find::Rule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::Find::Rule::DWG; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use File::Path qw(mkpath); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use File::Temp qw(tempdir); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Getopt::Std; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use IO::Barf qw(barf); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | Readonly::Scalar our $DR => 'dwgread'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | our $VERSION = 0.06; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my ($class, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Create object. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Object. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Run. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=12 SCAR=41.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Process arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $self->{'_opts'} = { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 'd' => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 'f' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'h' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'i' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'm' => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 's' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'v' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if (! getopts('d:fhim:sv:', $self->{'_opts'}) || @ARGV < 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not &getopts("d:fhim:sv:", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("d:fhim:sv:", $self->{"_opts"}) or @ARGV < 1
MC/DC0%0/3
not &getopts("d:fhim:sv:", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("d:fhim:sv:", $self->{"_opts"})
@ARGV < 1
$self->{"_opts"}{"h"}
Truth table25%1/4
not(A) or B or C
A= not &getopts("d:fhim:sv:", $self->{"_opts"})B= @ARGV < 1C= $self->{"_opts"}{"h"}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | || $self->{'_opts'}->{'h'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | print STDERR "Usage: $0 [-d test_dir] [-f] [-h] [-i] [-m match_string] [-s] [-v level] [--version] directory\n"; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | print STDERR "\t-d test_dir\tTest directory (default is directory in system tmp).\n"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | print STDERR "\t-f\t\tPrint file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | print STDERR "\t-h\t\tPrint help.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | print STDERR "\t-i\t\tIgnore errors.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | print STDERR "\t-m match_string\tMatch string (default is not defined).\n"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | print STDERR "\t-s\t\tSelect files which are symlinks too.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | print STDERR "\t-v level\tVerbosity level (default 1, min 0, max 9).\n"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | print STDERR "\t--version\tPrint version.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | print STDERR "\tdirectory\tDirectory with DWG files to test.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->{'_directory'} = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($self->{'_opts'}->{'v'} == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | warn "Verbosity level 0 hasn't detection of ERRORs.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $tmp_dir = $self->{'_opts'}->{'d'}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (defined $tmp_dir && ! -d $tmp_dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmp_dir and not -d $tmp_dir
MC/DC0%0/2
defined $tmp_dir and not -d $tmp_dir
defined $tmp_dir
not -d $tmp_dir
Truth table0%0/3
A and not(B)
A= defined $tmp_dirB= not -d $tmp_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | mkpath($tmp_dir); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (! defined $tmp_dir || ! -d $tmp_dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmp_dir and -d $tmp_dir
MC/DC0%0/2
defined $tmp_dir and -d $tmp_dir
defined $tmp_dir
-d $tmp_dir
Truth table0%0/3
A and B
A= defined $tmp_dirB= -d $tmp_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $tmp_dir = tempdir(CLEANUP => 1); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->{'_tmp_dir'} = $tmp_dir; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Verbose level. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $v = '-v'.$self->{'_opts'}->{'v'}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my @selected_files; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($self->{'_opts'}->{'s'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | @selected_files = File::Find::Rule->in($self->{'_directory'}); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | @selected_files = File::Find::Rule->dwg->not_symlink->in($self->{'_directory'}); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $file_num = 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | foreach my $dwg_file_in (@selected_files) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Copy DWG file to dir. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $dwg_file_out = catfile($tmp_dir, $file_num.'.dwg'); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | copy($dwg_file_in, $dwg_file_out); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # dwgread. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $dwgread = "$DR $v $dwg_file_out"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->_exec($dwgread, $file_num.'-dwgread', $dwg_file_in); | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # tmp directory cleanup immediately. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (! defined $self->{'_opts'}->{'d'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $tmp_glob_file = catfile($tmp_dir, $file_num); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my @glob_files = glob $tmp_glob_file.'*'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | unlink @glob_files; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $file_num++; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub _exec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ($self, $command, $log_prefix, $dwg_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($stdout, $stderr, $exit_code) = capture { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | system($command); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($exit_code) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (! $self->{'_opts'}->{'i'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | print STDERR "Cannot dwgread '$dwg_file'.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | print STDERR "\tCommand '$command' exit with $exit_code.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($stdout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $stdout_file = catfile($self->{'_tmp_dir'}, | |||||||||||||||||||||||||||||||||||||||||
| 126 | $log_prefix.'-stdout.log'); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | barf($stdout_file, $stdout); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ($stderr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $stderr_file = catfile($self->{'_tmp_dir'}, | |||||||||||||||||||||||||||||||||||||||||
| 131 | $log_prefix.'-stderr.log'); | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | barf($stderr_file, $stderr); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Report errors. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (! $self->{'_opts'}->{'i'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (my @num = ($stderr =~ m/ERROR/gms)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | print STDERR "dwgread '$dwg_file' has ".scalar @num." ERRORs\n"; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if (defined $self->{'_opts'}->{'m'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | foreach my $match_line ($self->_match_lines($stderr)) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($self->{'_opts'}->{'f'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | print $dwg_file.': '; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | print $match_line."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub _match_lines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_lines: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | foreach my $line (split m/\n/ms, $string) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($line =~ /$self->{'_opts'}->{'m'}/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | push @ret, $line; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return @ret; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||||||||||||||||