File Coverage

lib/Draft/Drawing.pm
Criterion Covered Total %
statement 23 37 62.1
branch 0 6 0.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 31 52 59.6


line stmt bran cond sub pod time code
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     1   5 use strict;
  1         2  
  1         28  
24 1     1   4 use warnings;
  1         1  
  1         20  
25              
26 1     1   4 use Draft;
  1         2  
  1         22  
27 1     1   383 use Draft::TkGui::Drawing;
  1         3  
  1         25  
28 1     1   381 use File::Atomism;
  1         2  
  1         42  
29 1     1   2389 use File::Atomism::utils qw /Extension/;
  1         4  
  1         76  
30              
31             # FIXME shouldn't depend on Tk
32 1     1   7 use vars qw /@ISA/;
  1         2  
  1         233  
33             @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             {
54 1     1 0 2 my $self = shift;
55              
56 1         169 my ($freshfiles, $stalefiles) = $self->Scan;
57              
58 0           for my $file (@{$stalefiles})
  0            
59             {
60 0           my $key = $self->{_path} . $file;
61 0 0         delete $self->{$key} if ($self->{$key});
62             }
63              
64 0           for my $file (@{$freshfiles})
  0            
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 0         $@ and next;
72              
73 0 0         $self->{$key} = eval "Draft::Protozoa::$type->new (\"$key\")"
74             unless exists $self->{$key};
75            
76 0           $self->{$key}->Read;
77 0           $self->{$key}->Process;
78             }
79             }
80              
81             1;