| 1 | package Draft::Protozoa::Eml; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | Draft::Protozoa::Eml - CAD drawing-object base class | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | This class is DEPRECATED, use YAML formatted file instead. | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | A CAD drawing object that consists of a single file that resembles | ||||||||||||||||||||
| 12 | an rfc822 email message. | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | If you find yourself using this base-class directly, then you are | ||||||||||||||||||||
| 17 | probably doing something wrong. | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | ▶ | use File::Atomism::utils qw /TempFilename Journal/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =pod | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 USAGE | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | Create an object by supplying the 'new' method with a file-path: | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | use Draft::Drawing::Eml; | ||||||||||||||||||||
| 33 | my $foo = Draft::Drawing::Eml->new ('/path/to/file.eml'); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | sub new | ||||||||||||||||||||
| 38 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 39 | 3 | my $class = shift; | |||||||||||||||||||
| 40 | 3 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 41 | 3 | my $self = bless {}, $class; | |||||||||||||||||||
| 42 | 3 | $self->{_path} = shift; | |||||||||||||||||||
| 43 | 3 | return $self; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =pod | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | Read/Parse an existing file with the Read method: | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | $foo->Read; | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Currently the file-format is a simple series of key->value | ||||||||||||||||||||
| 53 | declarations, one per line: | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | Pi: 3.1418 | ||||||||||||||||||||
| 56 | Author: Plato | ||||||||||||||||||||
| 57 | Author: Descartes | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | This might become a perl structure like this: | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | '/path/to/file.eml' => bless( { | ||||||||||||||||||||
| 62 | 'pi' => [ '3.1418' ], | ||||||||||||||||||||
| 63 | 'author' => [ 'Plato', 'Descartes' ], | ||||||||||||||||||||
| 64 | '_path' => '/path/to/file.eml' | ||||||||||||||||||||
| 65 | }, 'Draft::Drawing::Eml' ) | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | sub Read | ||||||||||||||||||||
| 70 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
Read: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | 3 | my $self = shift; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 3 | my $data = LoadFile ($self->{_path}); | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 3 | my $newclass = "Draft::Protozoa::Eml::". $self->Type ($data) ."::". $self->Version ($data); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 2 | ▶ | eval "use $newclass"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 78 | 3 | ▶ | $@ and return 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 3 | bless $self, $newclass; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 3 | $self->_parse ($data); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub LoadFile | ||||||||||||||||||||
| 86 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
LoadFile: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 87 | 3 | my $path = shift; | |||||||||||||||||||
| 88 | 3 | ▶ | open FILE, "<". $path or warn $path ." not found.\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 3 | my @lines = <FILE>; | |||||||||||||||||||
| 90 | 3 | close FILE; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 3 | my $data; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | # FIXME: should stop processing on first blank line | ||||||||||||||||||||
| 95 | # FIXME: should join lines prefixed with whitespace | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 3 | for my $line (@lines) | |||||||||||||||||||
| 98 | { | ||||||||||||||||||||
| 99 | 29 | chomp $line; | |||||||||||||||||||
| 100 | 29 | my ($key, $value) = split (':', $line); | |||||||||||||||||||
| 101 | 29 | $key = lc ($key); | |||||||||||||||||||
| 102 | 29 | $value =~ s/^ +//; | |||||||||||||||||||
| 103 | 29 | push @{$data->{$key}}, $value; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 3 | return $data; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =pod | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Objects can be moved in the world-space: | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | $foo->Move ([10, 5, 0]); | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | This edits the file on the filesystem in one atomic operation. This | ||||||||||||||||||||
| 116 | is a permanent operation - If you find that you didn't want to move | ||||||||||||||||||||
| 117 | the object, you might want to investigate using cvs for your data. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | sub Move | ||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
Move: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||
| 124 | 0 | my $vec = shift; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | open FILE, "<". $self->{_path} or warn $self->{_path} ." not found.\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | 0 | my @lines = <FILE>; | |||||||||||||||||||
| 128 | 0 | close FILE; | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | my $temp = TempFilename ($self->{_path}); | |||||||||||||||||||
| 131 | 0 | open FILE, ">". $temp; | |||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 0 | my $done; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 0 | for my $line (@lines) | |||||||||||||||||||
| 136 | { | ||||||||||||||||||||
| 137 | 0 | my ($key, $value) = split ': ', $line; | |||||||||||||||||||
| 138 | 0 | ▶ | $done->{$key} = 0 unless $done->{$key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | ▶ | if ($key =~ /^[0-9]+$/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | { | ||||||||||||||||||||
| 142 | 0 | $value += $vec->[$done->{$key}]; | |||||||||||||||||||
| 143 | 0 | $line = "$key: $value\n"; | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | $done->{$key}++; | |||||||||||||||||||
| 147 | 0 | print FILE $line; | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | ▶ | close FILE || return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | Journal ([[$self->{_path}, $temp]]); | |||||||||||||||||||
| 153 | 0 | rename $temp, $self->{_path}; | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | sub _capitalise | ||||||||||||||||||||
| 157 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
_capitalise: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 158 | 6 | my $self = shift; | |||||||||||||||||||
| 159 | 6 | my $word = shift; | |||||||||||||||||||
| 160 | 6 | my $first = substr ($word, 0, 1, ''); | |||||||||||||||||||
| 161 | 6 | return uc ($first) . lc ($word); | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =pod | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | Query the type and version of the object like so: | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | my $type = $self->Type ($foo); | ||||||||||||||||||||
| 169 | my $version = $self->Version ($foo); | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | sub Type | ||||||||||||||||||||
| 174 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
Type: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 175 | 3 | my $self = shift; | |||||||||||||||||||
| 176 | 3 | my $data = shift; | |||||||||||||||||||
| 177 | 3 | ▶ | my $type = $data->{type}->[0] || 'unknown'; | ||||||||||||||||||
|
Condition50%1/2
$data->{'type'}[0] || 'unknown'
MC/DC0%0/1
$data->{'type'}[0] || 'unknown'
$data->{'type'}[0]
Truth table50%1/2
A
A= $data->{'type'}[0]
| |||||||||||||||||||||
| 178 | 3 | $type =~ s/ .*//; | |||||||||||||||||||
| 179 | 3 | $type =~ s/[^a-z0-9_]//gi; | |||||||||||||||||||
| 180 | 3 | $self->_capitalise ($type); | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | sub Version | ||||||||||||||||||||
| 184 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
Version: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 185 | 3 | my $self = shift; | |||||||||||||||||||
| 186 | 3 | my $data = shift; | |||||||||||||||||||
| 187 | 3 | ▶ | my $version = $data->{version}->[0] || 'draft1'; | ||||||||||||||||||
|
Condition50%1/2
$data->{'version'}[0] || 'draft1'
MC/DC0%0/1
$data->{'version'}[0] || 'draft1'
$data->{'version'}[0]
Truth table50%1/2
A
A= $data->{'version'}[0]
| |||||||||||||||||||||
| 188 | 3 | $version =~ s/ .*//; | |||||||||||||||||||
| 189 | 3 | $version =~ s/[^a-z0-9_]//gi; | |||||||||||||||||||
| 190 | 3 | $self->_capitalise ($version); | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | #sub Process {} | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | #sub Draw {} | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 2 | 1; | |||||||||||||||||||