File Coverage

lib/Object/Meta/File.pm
Criterion Covered Total %
statement 21 21 100.0
branch 8 10 80.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 4 4 100.0
total 39 43 90.7


line stmt bran cond sub pod time code
1             #
2             # @author Bodo (Hugo) Barwich
3             # @version 2026-01-29
4             # @package Object::Meta
5             # @subpackage lib/Object/Meta/File.pm
6              
7             # This Module defines Classes to manage Data in an indexed List
8             #
9             #---------------------------------
10             # Requirements:
11             #
12             #---------------------------------
13             # Features:
14             #
15              
16             #==============================================================================
17             # The Object::Meta::File Package
18              
19             =head1 NAME
20              
21             Object::Meta::File - Library to recognise a special C field from the raw data
22              
23             =cut
24              
25             package Object::Meta::File;
26              
27             #----------------------------------------------------------------------------
28             #Dependencies
29              
30 3     3   129723 use parent 'Object::Meta::Named';
  3         266  
  3         51  
31              
32             =head1 DESCRIPTION
33              
34             C implements a class which adds a C and a C field
35             to the raw data which can be used to index the C entries.
36             It works exactly like the C class.
37              
38             Additionally a C meta data field will be created for indexation and lookup.
39              
40             The C meta data field becomes the index field.
41              
42             =cut
43              
44             #----------------------------------------------------------------------------
45             #Constructors
46              
47             =head1 METHODS
48              
49             =head2 Constructor
50              
51             =head3 new ( [ DATA ] )
52              
53             This is the constructor for a new C object.
54             It creates a new object from B which is passed in a hash key / value pairs.
55              
56             B
57              
58             =over 4
59              
60             =item C
61              
62             The B which is passed in a hash key / value pairs.
63              
64             If a C field is present it will be used to index the entry.
65              
66             If a C field is present it will be passed to the C
67             method.
68              
69             =back
70              
71             See L|Object::Meta::Named/"new ( [ DATA ] )">
72              
73             =cut
74              
75             sub new {
76 8   33 8 1 184518 my $class = ref( $_[0] ) || $_[0];
77              
78             #Take the Method Parameters
79 8         41 my %hshprms = @_[ 1 .. $#_ ];
80              
81 8         61 my $self = $class->SUPER::new(%hshprms);
82              
83 8 100       17 if ( defined $hshprms{'directoryname'} ) {
84 5         11 Object::Meta::File::setDirectoryName( $self, $hshprms{'directoryname'} );
85             }
86             else {
87 3         28 Object::Meta::File::setDirectoryName $self;
88             }
89              
90             #Give the Object back
91 8         28 return $self;
92             }
93              
94             #----------------------------------------------------------------------------
95             #Administration Methods
96              
97             =head2 Administration Methods
98              
99             =head3 set ( DATA )
100              
101             This overrides the base method C to recognize the
102             C and C field.
103              
104             See L|Object::Meta::Named/"set ( DATA )">
105              
106             See L|Object::Meta/"set ( DATA )">
107              
108             =cut
109              
110             sub set {
111 1     1 1 884 my ( $self, %hshprms ) = @_;
112              
113 1 50       4 if ( defined $hshprms{'directoryname'} ) {
114 1         4 Object::Meta::File::setDirectoryName( $self, delete $hshprms{'directoryname'} );
115             }
116              
117 1         4 Object::Meta::Named::set( $self, %hshprms );
118             }
119              
120             =head3 setDirectoryName ( [ DIRECTORY ] )
121              
122             This will create a C field in the raw data.
123              
124             B
125              
126             =over 4
127              
128             =item C
129              
130             The string value for the directory name of the object.
131              
132             If C is empty or is undefined it will empty the C field.
133              
134             If C does not have a trailing slash C< / > it will be added.
135              
136             =back
137              
138             =cut
139              
140             sub setDirectoryName {
141 10     10 1 26 my $self = $_[0];
142              
143 10 100       21 if ( scalar(@_) > 1 ) {
144 7         13 Object::Meta::set( $self, 'directoryname', $_[1] );
145             }
146             else {
147 3         6 Object::Meta::set( $self, 'directoryname', '' );
148             }
149              
150 10 100       23 if ( $self->[Object::Meta::LIST_DATA]{'directoryname'} ne '' ) {
151             $self->[Object::Meta::LIST_DATA]{'directoryname'} .= '/'
152 7 50       35 unless ( $self->[Object::Meta::LIST_DATA]{'directoryname'} =~ m#/$# );
153              
154             }
155             }
156              
157             #----------------------------------------------------------------------------
158             #Consultation Methods
159              
160             =head2 Consultation Methods
161              
162             =head3 getDirectoryName ()
163              
164             Returns the content of the C field.
165              
166             =cut
167              
168             sub getDirectoryName {
169 6     6 1 30 return $_[0]->[Object::Meta::LIST_DATA]{'directoryname'};
170             }
171              
172             return 1;