| 1 | package App::DWG::Sort; | ||
| 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 | 0 | ▶ | use CAD::AutoCAD::Detect qw(detect_dwg_file); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use Class::Utils qw(set_params); | ||
| 8 | use Error::Pure qw(err); | ||
| 9 | use File::Copy qw(move); | ||
| 10 | use File::Find::Rule; | ||
| 11 | use File::Find::Rule::DWG; | ||
| 12 | use File::Path qw(make_path); | ||
| 13 | use File::Spec::Functions qw(catfile); | ||
| 14 | use Getopt::Std; | ||
| 15 | |||
| 16 | our $VERSION = 0.01; | ||
| 17 | |||
| 18 | # Constructor. | ||
| 19 | sub new { | ||
| 20 | my ($class, @params) = @_; | ||
| 21 | |||
| 22 | # Create object. | ||
| 23 | my $self = bless {}, $class; | ||
| 24 | |||
| 25 | # Process parameters. | ||
| 26 | set_params($self, @params); | ||
| 27 | |||
| 28 | # Object. | ||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | # Run. | ||
| 33 | sub run { | ||
| 34 | my $self = shift; | ||
| 35 | |||
| 36 | # Process arguments. | ||
| 37 | $self->{'_opts'} = { | ||
| 38 | 'h' => 0, | ||
| 39 | }; | ||
| 40 | if (! getopts('h', $self->{'_opts'}) || @ARGV < 1 | ||
| 41 | || $self->{'_opts'}->{'h'}) { | ||
| 42 | |||
| 43 | print STDERR "Usage: $0 [-h] [--version] directory\n"; | ||
| 44 | print STDERR "\t-h\t\tPrint help.\n"; | ||
| 45 | print STDERR "\t--version\tPrint version.\n"; | ||
| 46 | print STDERR "\tdirectory\tDirectory with DWG files.\n"; | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | $self->{'_dir'} = shift @ARGV; | ||
| 50 | |||
| 51 | foreach my $file (File::Find::Rule->dwg->in($self->{'_dir'})) { | ||
| 52 | my $magic = detect_dwg_file($file); | ||
| 53 | my $magic_dir = catfile($self->{'_dir'}, $magic); | ||
| 54 | if (! -r $magic_dir) { | ||
| 55 | make_path($magic_dir); | ||
| 56 | } | ||
| 57 | move($file, $magic_dir); | ||
| 58 | } | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | |||
| 66 | __END__ | ||