| 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<directoryname> field from the raw data | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | package Object::Meta::File; | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 28 | #Dependencies | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 3 | ▶ | use parent 'Object::Meta::Named'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | C<Object::Meta::File> implements a class which adds a C<name> and a C<directoryname> field | ||||||||||||||||||||
| 35 | to the raw data which can be used to index the C<Object::Meta> entries. | ||||||||||||||||||||
| 36 | It works exactly like the C<Object::Meta::Named> class. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | Additionally a C<hash> meta data field will be created for indexation and lookup. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | The C<hash> 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::Meta::File> object. | ||||||||||||||||||||
| 54 | It creates a new object from B<raw data> which is passed in a hash key / value pairs. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | B<Parameters:> | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =over 4 | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =item C<DATA> | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | The B<raw data> which is passed in a hash key / value pairs. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | If a C<name> field is present it will be used to index the entry. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | If a C<directoryname> field is present it will be passed to the C<setDirectoryName()> | ||||||||||||||||||||
| 67 | method. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =back | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | See L<Method C<Object::Meta::Named::new()>|Object::Meta::Named/"new ( [ DATA ] )"> | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 8 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 76 | 8 | ▶ | my $class = ref( $_[0] ) || $_[0]; | ||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | #Take the Method Parameters | ||||||||||||||||||||
| 79 | 8 | my %hshprms = @_[ 1 .. $#_ ]; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 8 | my $self = $class->SUPER::new(%hshprms); | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 8 | ▶ | if ( defined $hshprms{'directoryname'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 5 | Object::Meta::File::setDirectoryName( $self, $hshprms{'directoryname'} ); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||
| 87 | 3 | Object::Meta::File::setDirectoryName $self; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | #Give the Object back | ||||||||||||||||||||
| 91 | 8 | 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<Object::Meta::Named::set()> to recognize the | ||||||||||||||||||||
| 102 | C<name> and C<directoryname> field. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | See L<Method C<Object::Meta::Named::set()>|Object::Meta::Named/"set ( DATA )"> | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | See L<Method C<Object::Meta::set()>|Object::Meta/"set ( DATA )"> | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 1 | ▶ | sub set { | ||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 111 | 1 | my ( $self, %hshprms ) = @_; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | ▶ | if ( defined $hshprms{'directoryname'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 1 | Object::Meta::File::setDirectoryName( $self, delete $hshprms{'directoryname'} ); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | Object::Meta::Named::set( $self, %hshprms ); | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =head3 setDirectoryName ( [ DIRECTORY ] ) | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | This will create a C<directoryname> field in the raw data. | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | B<Parameters:> | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =over 4 | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =item C<DIRECTORY> | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | The string value for the directory name of the object. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | If C<DIRECTORY> is empty or is undefined it will empty the C<directoryname> field. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | If C<DIRECTORY> does not have a trailing slash C< / > it will be added. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =back | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 10 | ▶ | sub setDirectoryName { | ||||||||||||||||||
|
Subroutine
setDirectoryName: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 141 | 10 | my $self = $_[0]; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 10 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 7 | Object::Meta::set( $self, 'directoryname', $_[1] ); | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||
| 147 | 3 | Object::Meta::set( $self, 'directoryname', '' ); | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 10 | ▶ | if ( $self->[Object::Meta::LIST_DATA]{'directoryname'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | $self->[Object::Meta::LIST_DATA]{'directoryname'} .= '/' | ||||||||||||||||||||
| 152 | 7 | ▶ | unless ( $self->[Object::Meta::LIST_DATA]{'directoryname'} =~ m#/$# ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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<directoryname> field. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 6 | ▶ | sub getDirectoryName { | ||||||||||||||||||
|
Subroutine
getDirectoryName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 169 | 6 | return $_[0]->[Object::Meta::LIST_DATA]{'directoryname'}; | |||||||||||||||||||
| 170 | } | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 3 | return 1; | |||||||||||||||||||