| 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<DIRTYPE> 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<SGI::FAM> | ||||||||||||||||||||
| 24 | which monitors file addition, changes or deletions. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | our $VERSION = 0.1; | |||||||||||||||||||
| 32 | 1 | our $EVENT = undef; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | use vars qw /@ISA/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.4
Pod
undocumented
| |||||||||||||||||||||
| 49 | 1 | my $class = shift; | |||||||||||||||||||
| 50 | 1 | ▶ | $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
| |||||||||||||||||||||
| 51 | 1 | my $self = bless {}, $class; | |||||||||||||||||||
| 52 | 1 | $self->{_path} = shift; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | ▶ | open FILE, "<". $self->{_path} ."DIRTYPE" or warn $self->{_path} ." not found.\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 1 | my @lines = <FILE>; | |||||||||||||||||||
| 56 | 1 | close FILE; | |||||||||||||||||||
| 57 | 1 | chomp for (@lines); | |||||||||||||||||||
| 58 | 1 | $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 | my $newclass = "File::Atomism::". $self->Type; | |||||||||||||||||||
| 69 | 0 | ▶ | eval "use $newclass"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 70 | # FIXME should use bless to reclass as @ISA applies to all instances | ||||||||||||||||||||
| 71 | 1 | @ISA = eval "qw /$newclass/"; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | return $self; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub Capitalise | ||||||||||||||||||||
| 77 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
Capitalise: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||||||||||
| 79 | 1 | my $word = shift; | |||||||||||||||||||
| 80 | 1 | my $first = substr ($word, 0, 1, ''); | |||||||||||||||||||
| 81 | 1 | 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 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
Type: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 103 | 1 | my $self = shift; | |||||||||||||||||||
| 104 | 1 | ▶ | my $type = $self->{_dirtype}->[0] || 'protozoa'; | ||||||||||||||||||
|
Condition50%1/2
$self->{'_dirtype'}[0] || 'protozoa'
MC/DC0%0/1
$self->{'_dirtype'}[0] || 'protozoa'
$self->{'_dirtype'}[0]
Truth table50%1/2
A
A= $self->{'_dirtype'}[0]
| |||||||||||||||||||||
| 105 | 1 | $type =~ s/ .*//; | |||||||||||||||||||
| 106 | 1 | $type =~ s/[^a-z0-9_]//gi; | |||||||||||||||||||
| 107 | 1 | $self->Capitalise ($type); | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | sub Version | ||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
Version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||
| 113 | 0 | my $version = $self->{_dirtype}->[0]; | |||||||||||||||||||
| 114 | 0 | ▶ | return 0 unless $version =~ / [^ ]/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 0 | $version =~ s/^[^ ]+ //; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | sub Description | ||||||||||||||||||||
| 119 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
Description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||
| 121 | 0 | $self->{_dirtype}->[1]; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | L<Draft>, L<File::Atomism::Protozoa>, L<SGI::FAM> | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head1 AUTHORS | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =item * | ||||||||||||||||||||
| 131 | Bruno Postle <bruno@postle.net> | ||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||
| 142 | |||||||||||||||||||||