| 1 | package Draft::Drawing; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Draft::Drawing - CAD drawing type | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | A directory that contains multiple drawing elements | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | A simple file-system directory/folder that contains any number of | ||||||||||
| 14 | drawing objects, represented by files; and optionally, any number of | ||||||||||
| 15 | further drawings represented by subdirectories. | ||||||||||
| 16 | |||||||||||
| 17 | Note that this is not completely analogous to a traditional | ||||||||||
| 18 | monolithic CAD file format, as blocks/symbols associated with a | ||||||||||
| 19 | drawing are complete drawings in their own right. | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use Draft; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use Draft::TkGui::Drawing; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ▶ | use File::Atomism; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use File::Atomism::utils qw /Extension/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | # FIXME shouldn't depend on Tk | ||||||||||
| 32 | 1 | ▶ | use vars qw /@ISA/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 1 | @ISA = qw /Draft::TkGui::Drawing File::Atomism/; | |||||||||
| 34 | |||||||||||
| 35 | =pod | ||||||||||
| 36 | |||||||||||
| 37 | =head1 USAGE | ||||||||||
| 38 | |||||||||||
| 39 | Read a drawing into memory, or simply update an already-loaded | ||||||||||
| 40 | drawing by using the Read method: | ||||||||||
| 41 | |||||||||||
| 42 | $drawing->Read; | ||||||||||
| 43 | |||||||||||
| 44 | Note that this method will only access the filesystem if files have | ||||||||||
| 45 | actually changed or are new - Feel free to call this method as often | ||||||||||
| 46 | as you like as it has very little performance overhead. | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | # FIXME sometimes doesn't delete objects when files are removed | ||||||||||
| 51 | |||||||||||
| 52 | sub Read | ||||||||||
| 53 | 1 | ▶ | { | ||||||||
|
Subroutine
Read: called CC=6 SCAR=35.0
Pod
undocumented
| |||||||||||
| 54 | 1 | my $self = shift; | |||||||||
| 55 | |||||||||||
| 56 | 1 | my ($freshfiles, $stalefiles) = $self->Scan; | |||||||||
| 57 | |||||||||||
| 58 | 0 | for my $file (@{$stalefiles}) | |||||||||
| 59 | { | ||||||||||
| 60 | 0 | my $key = $self->{_path} . $file; | |||||||||
| 61 | 0 | ▶ | delete $self->{$key} if ($self->{$key}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | for my $file (@{$freshfiles}) | |||||||||
| 65 | { | ||||||||||
| 66 | 0 | my $key = $self->{_path} . $file; | |||||||||
| 67 | |||||||||||
| 68 | 0 | my $type = Extension ($file); | |||||||||
| 69 | 0 | $type = $self->Capitalise ($type); | |||||||||
| 70 | 0 | eval "use Draft::Protozoa::$type"; | |||||||||
| 71 | 0 | ▶ | $@ and next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | $self->{$key} = eval "Draft::Protozoa::$type->new (\"$key\")" | ||||||||||
| 74 | 0 | ▶ | unless exists $self->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 0 | $self->{$key}->Read; | |||||||||
| 77 | 0 | $self->{$key}->Process; | |||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | 1; | |||||||||