File Coverage

blib/lib/D64/Disk/Status/Factory.pm
Criterion Covered Total %
statement 42 42 100.0
branch 8 8 100.0
condition 2 2 100.0
subroutine 10 10 100.0
pod 1 1 100.0
total 63 63 100.0


line stmt bran cond sub pod time code
1             package D64::Disk::Status::Factory;
2              
3             =head1 NAME
4              
5             D64::Disk::Status::Factory - Factory class to create L objects for all existing 1541 DOS error messages
6              
7             =head1 SYNOPSIS
8              
9             use D64::Disk::Status::Factory;
10              
11             # Create a new disk status object instance:
12             my $status = D64::Disk::Status::Factory->new($error_code);
13              
14             =head1 DESCRIPTION
15              
16             C is a factory class to create C objects for all existing 1541 DOS error messages.
17              
18             =head1 METHODS
19              
20             =cut
21              
22 1     1   49046 use bytes;
  1         13  
  1         5  
23 1     1   29 use strict;
  1         3  
  1         68  
24 1     1   2177 use utf8;
  1         10  
  1         4  
25 1     1   32 use warnings;
  1         3  
  1         127  
26              
27             our $VERSION = '0.03';
28              
29 1     1   829 use D64::Disk::Status;
  1         10  
  1         22  
30 1     1   2007 use Data::Dumper;
  1         10999  
  1         73  
31 1     1   806 use Readonly;
  1         3778  
  1         931  
32              
33             our %errors = (
34             0 => {
35             error => 'OK',
36             message => 'OK',
37             description => '',
38             },
39             1 => {
40             error => 'FILES SCRATCHED',
41             message => 'files scratched',
42             description => '',
43             },
44             20 => {
45             error => 'READ ERROR',
46             message => 'block header not found',
47             description => 'The disk controller is unable to locate the header of the requested data block. Caused by an illegal block number, or the header has been destroyed.',
48             },
49             21 => {
50             error => 'READ ERROR',
51             message => 'sync character not found',
52             description => 'The disk controller is unable to detect a sync mark on the desired track. Caused by misalignment of the read/writer head, no diskette is present, or unformatted or improperly seated diskette.',
53             },
54             22 => {
55             error => 'READ ERROR',
56             message => 'data block not present',
57             description => 'The disk controller has been requested to read or verify a data block that was not properly written. This error message occurs in conjunction with the BLOCK commands and indicates an illegal track and/or block request.',
58             },
59             23 => {
60             error => 'READ ERROR',
61             message => 'checksum error in data block',
62             description => 'This error message indicates that there is an error in one or more of the data bytes. The data has been read into the DOS memory, but the checksum over the data is in error.',
63             },
64             24 => {
65             error => 'READ ERROR',
66             message => 'byte decoding error',
67             description => 'The data or header has been read into the DOS memory, but a hardware error has been created due to an invalid bit pattern in the data byte.',
68             },
69             25 => {
70             error => 'WRITE ERROR',
71             message => 'write-verify error',
72             description => 'This message is generated if the controller detects a mismatch between the written data and the data in the DOS memory.',
73             },
74             26 => {
75             error => 'WRITE PROTECT ON',
76             message => 'attempt to write with write protect on',
77             description => 'This message is generated when the controller has been requested to write a data block while the write protect switch is depressed.',
78             },
79             27 => {
80             error => 'READ ERROR',
81             message => 'checksum error in header',
82             description => 'The controller has detected an error in the header of the requested data block. The block has not been read into the DOS memory.',
83             },
84             28 => {
85             error => 'WRITE ERROR',
86             message => 'data extends into next block',
87             description => 'The controller attempts to detect the sync mark of the next header after writing a data block. If the sync mark does not appear within a predetermined time, the error message is generated. The error is caused by a bad diskette format (the data extends into the next block), or by hardware failure.',
88             },
89             29 => {
90             error => 'DISK ID MISMATCH',
91             message => 'disk id mismatch',
92             description => 'This message is generated when the controller has been requested to access a diskette which has not been initialized. The message can also occur if a diskette has a bad header.',
93             },
94             30 => {
95             error => 'SYNTAX ERROR',
96             message => 'general syntax error',
97             description => 'The DOS cannot interpret the command sent to the command channel. Typically, this is caused by an illegal number of file names, or patterns are illegally used. For example, two file names may appear on the left side of the COPY command.',
98             },
99             31 => {
100             error => 'SYNTAX ERROR',
101             message => 'invalid command',
102             description => 'The DOS does not recognize the command. The command must start in the first position.',
103             },
104             32 => {
105             error => 'SYNTAX ERROR',
106             message => 'long line',
107             description => 'The command sent is longer than 58 characters.',
108             },
109             33 => {
110             error => 'SYNTAX ERROR',
111             message => 'invalid filename',
112             description => 'Pattern matching is invalidly used in the OPEN or SAVE command.',
113             },
114             34 => {
115             error => 'SYNTAX ERROR',
116             message => 'no file given',
117             description => 'The file name was left out of a command or the DOS does not recognize it as such. Typically, a colon (:) has been left out of the command.',
118             },
119             39 => {
120             error => 'FILE NOT FOUND',
121             message => 'command file not found',
122             description => 'This error may result if the command sent to command channel (secondary address 15) is unrecognized by the DOS.',
123             },
124             50 => {
125             error => 'RECORD NOT PRESENT',
126             message => 'record not present',
127             description => 'Result of disk reading past the last record through INPUT#, or GET# commands. This message will also occur after positioning to a record beyond end of file in a relative file. If the intent is to expand the file by adding the new record (with a PRINT# command), the error message may be ignored. INPUT or GET should not be attempted after this error is detected without first repositioning.',
128             },
129             51 => {
130             error => 'OVERFLOW IN RECORD',
131             message => 'overflow in record',
132             description => 'PRINT# statement exceeds record boundary. Information is cut off. Since the carriage return is sent as a record terminator is counted in the record size. This message will occur if the total characters in the record (including the final carriage return) exceed the defined size.',
133             },
134             52 => {
135             error => 'FILE TOO LARGE',
136             message => 'file too large',
137             description => 'Record position within a relative file indicates that disk overflow will result.',
138             },
139             60 => {
140             error => 'WRITE FILE OPEN',
141             message => 'file open for write',
142             description => 'This message is generated when a write file that has not been closed is being opened for reading.',
143             },
144             61 => {
145             error => 'FILE NOT OPEN',
146             message => 'file not open',
147             description => 'This message is generated when a file is being accessed that has not been opened in the DOS. Sometimes, in this case, a message is not generated, the request is simply ignored.',
148             },
149             62 => {
150             error => 'FILE NOT FOUND',
151             message => 'file not found',
152             description => 'The requested file does not exist on the indicated drive.',
153             },
154             63 => {
155             error => 'FILE EXISTS',
156             message => 'file exists',
157             description => 'The file name of the file being created already exists on the diskette.',
158             },
159             64 => {
160             error => 'FILE TYPE MISMATCH',
161             message => 'file type mismatch',
162             description => 'The file type does not match the file type in the directory entry for the requested file.',
163             },
164             65 => {
165             error => 'NO BLOCK',
166             message => 'no block',
167             description => 'This message occurs in conjunction with the B-A command. It indicates that the block to be allocated has been previously allocated. The parameters indicate the track and sector available with the next highest number. If the parameters are zero (0), then all blocks higher in number are in use.',
168             },
169             66 => {
170             error => 'ILLEGAL TRACK OR SECTOR',
171             message => 'illegal track or sector',
172             description => 'The DOS has attempted to access a track or block which does not exist in the format being used. This may indicate a problem reading the pointer to the next block.',
173             },
174             67 => {
175             error => 'ILLEGAL TRACK OR SECTOR',
176             message => 'illegal system track or sector',
177             description => 'This special error message indicates an illegal system track or block.',
178             },
179             70 => {
180             error => 'NO CHANNEL',
181             message => 'no channels available',
182             description => 'The requested channel is not available, or all channels are in use. A maximum of five sequential files may be opened at one time to the DOS. Direct access channels may have six opened files.',
183             },
184             71 => {
185             error => 'DIR ERROR',
186             message => 'directory error',
187             description => 'The BAM does not match the internal count. There is a problem in the BAM allocation or the BAM has been overwritten in DOS memory. To correct this problem, reinitialize the diskette to restore the BAM in memory. Some active files may be terminated by the corrective action.',
188             },
189             72 => {
190             error => 'DISK FULL',
191             message => 'disk full or directory full',
192             description => 'Either the blocks on the diskette are used or the directory is at its entry limit. DISK FULL is sent when two blocks are available on the 1541 to allow the current file to be closed.',
193             },
194             73 => {
195             error => 'CBM DOS V2.6 1541',
196             message => 'power up message, or write attempt with dos mismatch',
197             description => 'DOS 1 and 2 are read compatible but not write compatible. Disks may be interchangeably read with either DOS, but a disk formatted on one version cannot be written upon with the other version because the format is different. This error is displayed whenever an attempt is made to write upon a disk which has been formatted in a non-compatible format. This message may also appear after power up.',
198             },
199             74 => {
200             error => 'DRIVE NOT READY',
201             message => 'drive not ready',
202             description => 'An attempt has been made to access the 1541 Single Drive Floppy Disk without any diskettes present in either drive.',
203             },
204             );
205              
206             our $errors;
207             if ($] < 5.008) {
208             eval q{ Readonly \\$errors => \\%errors; };
209             }
210             else {
211             eval q{ Readonly $errors => \\%errors; };
212             }
213              
214             =head2 new
215              
216             Create a new disk status object instance:
217              
218             my $status = D64::Disk::Status::Factory->new($error_code);
219              
220             C<$error_code> is one of pre-defined error codes for all existing CBM floppy error messages, and defaults to C<0> (which is no error, C status).
221              
222             =cut
223              
224             sub new {
225 12     12 1 5550 my ($class, @args) = @_;
226 12         32 my $status = $class->_init(@args);
227 7         17 return $status;
228             }
229              
230             sub _init {
231 12     12   20 my ($class, @args) = @_;
232              
233 12 100       28 unless (scalar (@args) <= 1) {
234 1         6 die sprintf q{Unable to create status object: Invalid number of arguments (%s)}, $class->_dump(\@args);
235             }
236              
237 11   100     30 my $code = shift (@args) || 0;
238              
239 11 100       23 if (ref $code) {
240 2         21 die sprintf q{Unable to create status object: Invalid argument type (%s)}, ref $code;
241             }
242              
243 9 100       43 unless ($code =~ m/^\d+$/) {
244 1         4 die sprintf q{Unable to create status object: Illegal argument value (%s)}, $class->_dump($code);
245             }
246              
247 8 100       34 unless (exists $errors->{$code}) {
248 1         8 die sprintf q{Unable to create status object: Invalid error code number (%s)}, $class->_dump($code);
249             }
250              
251 7         49 my %params = %{$errors->{$code}};
  7         17  
252 7         73 $params{code} = $code;
253              
254 7         32 my $status = D64::Disk::Status->new(%params);
255 7         21 return $status;
256             }
257              
258             sub _dump {
259 3     3   5 my ($class, $value) = @_;
260              
261 3         23 my $dump = Data::Dumper->new([$value])->Indent(0)->Terse(1)->Deepcopy(1)->Sortkeys(1)->Dump();
262              
263 3         319 return $dump;
264             }
265              
266             =head1 BUGS
267              
268             There are no known bugs at the moment. Please report any bugs or feature requests.
269              
270             =head1 EXPORT
271              
272             None. No method is exported into the caller's namespace neither by default nor explicitly.
273              
274             =head1 SEE ALSO
275              
276             L.
277              
278             =head1 AUTHOR
279              
280             Pawel Krol, Epawelkrol@cpan.orgE.
281              
282             =head1 VERSION
283              
284             Version 0.03 (2013-03-09)
285              
286             =head1 COPYRIGHT AND LICENSE
287              
288             Copyright 2013 by Pawel Krol Epawelkrol@cpan.orgE.
289              
290             This library is free open source software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
291              
292             PLEASE NOTE THAT IT COMES WITHOUT A WARRANTY OF ANY KIND!
293              
294             =cut
295              
296             1;
297              
298             __END__