File Coverage

lib/File/Atomism.pm
Criterion Covered Total %
statement 32 40 80.0
branch 1 4 25.0
condition 2 5 40.0
subroutine 7 9 77.7
pod 0 5 0.0
total 42 63 66.6


line stmt bran cond sub pod time code
1             package File::Atomism;
2              
3             =head1 NAME
4              
5             File::Atomism - atomised directory file formats
6              
7             =head1 SYNOPSIS
8              
9             A directory containing a number of files that are used collectively
10             as a random access data store.
11              
12             =head1 DESCRIPTION
13              
14             An atomised directory can be identified by a F file located in
15             the root, this file contains the type and version on the first line
16             (separated by the first whitespace) and an explanatory URL on the
17             second line.
18              
19             Alternatively, atomised directories could be identified using
20             heuristics - The existence of cur/ new/ and tmp/ folders would
21             identify a Maildir.
22              
23             Typically access to the individual files is provided via L
24             which monitors file addition, changes or deletions.
25              
26             =cut
27              
28 1     1   14 use strict;
  1         1  
  1         33  
29 1     1   4 use warnings;
  1         2  
  1         55  
30              
31             our $VERSION = 0.1;
32             our $EVENT = undef;
33              
34 1     1   5 use vars qw /@ISA/;
  1         2  
  1         1644  
35              
36             =pod
37              
38             =head1 USAGE
39              
40             Create an atomised directory object like so:
41              
42             use File::Atomism;
43             my $drawing = File::Atomism->new ('/path/to/drawing/');
44              
45             =cut
46              
47             sub new
48             {
49 1     1 0 3 my $class = shift;
50 1   33     6 $class = ref $class || $class;
51 1         3 my $self = bless {}, $class;
52 1         8 $self->{_path} = shift;
53              
54 1 50       40 open FILE, "<". $self->{_path} ."DIRTYPE" or warn $self->{_path} ." not found.\n";
55 1         16 my @lines = ;
56 1         10 close FILE;
57 1         5 chomp for (@lines);
58 1         3 $self->{_dirtype} = \@lines;
59              
60             =pod
61              
62             An attempt is made to reclass the object according to the "type".
63             For instance if the type is "protozoa", the object will be given the
64             class "File::Atomism::Protozoa".
65              
66             =cut
67              
68 1         8 my $newclass = "File::Atomism::". $self->Type;
69 1     1   488 eval "use $newclass";
  0         0  
  0         0  
  1         56  
70             # FIXME should use bless to reclass as @ISA applies to all instances
71 1         40 @ISA = eval "qw /$newclass/";
72              
73 1         8 return $self;
74             }
75              
76             sub Capitalise
77             {
78 1     1 0 2 my $self = shift;
79 1         2 my $word = shift;
80 1         3 my $first = substr ($word, 0, 1, '');
81 1         5 return uc ($first) . lc ($word);
82             }
83              
84             =pod
85              
86             A canonicalised and sanitised "type" can be retrieved like so:
87              
88             my $type = $dir->Type;
89              
90             The unsanitised version string (if it exists) can be retrieved
91             similarly:
92              
93             my $version = $dir->Version;
94              
95             The explanatory URL can be accessed:
96              
97             my $description = $dir->Description;
98              
99             =cut
100              
101             sub Type
102             {
103 1     1 0 4 my $self = shift;
104 1   50     5 my $type = $self->{_dirtype}->[0] || 'protozoa';
105 1         5 $type =~ s/ .*//;
106 1         3 $type =~ s/[^a-z0-9_]//gi;
107 1         9 $self->Capitalise ($type);
108             }
109              
110             sub Version
111             {
112 0     0 0   my $self = shift;
113 0           my $version = $self->{_dirtype}->[0];
114 0 0         return 0 unless $version =~ / [^ ]/;
115 0           $version =~ s/^[^ ]+ //;
116             }
117              
118             sub Description
119             {
120 0     0 0   my $self = shift;
121 0           $self->{_dirtype}->[1];
122             }
123              
124             =head1 SEE ALSO
125              
126             L, L, L
127              
128             =head1 AUTHORS
129              
130             =item *
131             Bruno Postle
132              
133             =head1 COPYRIGHT
134              
135             Copyright (c) 2004 Bruno Postle. This module is free software; you can
136             redistribute it and/or modify it under the same terms as Perl itself.
137              
138             =cut
139              
140              
141             1;
142