File Coverage

blib/lib/App/DWG/Sort.pm
Criterion Covered Total %
statement 45 53 84.9
branch 1 4 25.0
condition 2 6 33.3
subroutine 13 13 100.0
pod 2 2 100.0
total 63 78 80.7


line stmt bran cond sub pod time code
1             package App::DWG::Sort;
2              
3 4     4   166015 use strict;
  4         8  
  4         142  
4 4     4   35 use warnings;
  4         7  
  4         225  
5              
6 4     4   2255 use CAD::AutoCAD::Detect qw(detect_dwg_file);
  4         91733  
  4         90  
7 4     4   309 use Class::Utils qw(set_params);
  4         13  
  4         228  
8 4     4   20 use Error::Pure qw(err);
  4         12  
  4         166  
9 4     4   2558 use File::Copy qw(move);
  4         36522  
  4         342  
10 4     4   2477 use File::Find::Rule;
  4         43799  
  4         40  
11 4     4   2930 use File::Find::Rule::DWG;
  4         2383  
  4         41  
12 4     4   316 use File::Path qw(make_path);
  4         8  
  4         940  
13 4     4   2094 use File::Spec::Functions qw(catfile);
  4         5497  
  4         392  
14 4     4   2276 use Getopt::Std;
  4         12301  
  4         1654  
15              
16             our $VERSION = 0.01;
17              
18             # Constructor.
19             sub new {
20 2     2 1 818812 my ($class, @params) = @_;
21              
22             # Create object.
23 2         6 my $self = bless {}, $class;
24              
25             # Process parameters.
26 2         62 set_params($self, @params);
27              
28             # Object.
29 2         21 return $self;
30             }
31              
32             # Run.
33             sub run {
34 1     1 1 1 my $self = shift;
35              
36             # Process arguments.
37 1         7 $self->{'_opts'} = {
38             'h' => 0,
39             };
40 1 50 33     7 if (! getopts('h', $self->{'_opts'}) || @ARGV < 1
      33        
41             || $self->{'_opts'}->{'h'}) {
42              
43 1         97 print STDERR "Usage: $0 [-h] [--version] directory\n";
44 1         21 print STDERR "\t-h\t\tPrint help.\n";
45 1         18 print STDERR "\t--version\tPrint version.\n";
46 1         8 print STDERR "\tdirectory\tDirectory with DWG files.\n";
47 1         4 return 1;
48             }
49 0           $self->{'_dir'} = shift @ARGV;
50              
51 0           foreach my $file (File::Find::Rule->dwg->in($self->{'_dir'})) {
52 0           my $magic = detect_dwg_file($file);
53 0           my $magic_dir = catfile($self->{'_dir'}, $magic);
54 0 0         if (! -r $magic_dir) {
55 0           make_path($magic_dir);
56             }
57 0           move($file, $magic_dir);
58             }
59              
60 0           return 0;
61             }
62              
63             1;
64              
65              
66             __END__