| 1 | package Concierge::Users::YAML v0.9.4; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use YAML::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use File::Path qw/ make_path /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use parent qw/ Concierge::Users::Meta /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # ABSTRACT: YAML file backend for Concierge::Users | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ============================================================================== | ||||||||||||||||||||||||||||
| 12 | # Configure Class Method - One-time setup (called by Users->setup) | ||||||||||||||||||||||||||||
| 13 | # ============================================================================== | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 19 | ▶ | sub configure { | ||||||||||||||||||||||||||
|
Subroutine
configure: called CC=7 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 19 | my ($class, $setup_config) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Extract storage_dir | ||||||||||||||||||||||||||||
| 19 | 19 | my $storage_dir = $setup_config->{storage_dir}; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # For YAML backend, storage is just the directory | ||||||||||||||||||||||||||||
| 22 | # No additional setup needed beyond ensuring storage_dir exists | ||||||||||||||||||||||||||||
| 23 | # (already done by Users->setup before calling configure) | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Create temporary object for archiving | ||||||||||||||||||||||||||||
| 26 | my $temp_backend = bless { | ||||||||||||||||||||||||||||
| 27 | storage_dir => $storage_dir, | ||||||||||||||||||||||||||||
| 28 | fields => $setup_config->{fields} || [], | ||||||||||||||||||||||||||||
| 29 | field_definitions => $setup_config->{field_definitions}, | ||||||||||||||||||||||||||||
| 30 | 19 | ▶ | }, $class; | ||||||||||||||||||||||||||
|
Condition50%1/2
$setup_config->{'fields'} || []
MC/DC0%0/1
$setup_config->{'fields'} || []
$setup_config->{'fields'}
Truth table50%1/2
A
A= $setup_config->{'fields'}
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Check for existing YAML files and archive if present | ||||||||||||||||||||||||||||
| 33 | 19 | ▶ | if (opendir(my $dh, $storage_dir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 19 | ▶ | my @yaml_files = grep { /\.yaml$/ && -f "$storage_dir/$_" } readdir $dh; | ||||||||||||||||||||||||||
|
Condition66%2/3
/\.yaml$/u && -f "$storage_dir/$_"
MC/DC50%1/2
/\.yaml$/u && -f "$storage_dir/$_"
/\.yaml$/u
-f "$storage_dir/$_"
Truth table66%2/3
A && B
A= /\.yaml$/uB= -f "$storage_dir/$_"
| |||||||||||||||||||||||||||||
| 35 | 19 | closedir $dh; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Archive if YAML files exist | ||||||||||||||||||||||||||||
| 38 | 19 | ▶ | if (@yaml_files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 1 | my $archive_result = $temp_backend->_archive_user_data(); | |||||||||||||||||||||||||||
| 40 | 1 | ▶ | unless ($archive_result->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | return { | ||||||||||||||||||||||||||||
| 42 | success => 0, | ||||||||||||||||||||||||||||
| 43 | message => $archive_result->{message}, | ||||||||||||||||||||||||||||
| 44 | 0 | }; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Return success with config | ||||||||||||||||||||||||||||
| 50 | return { | ||||||||||||||||||||||||||||
| 51 | success => 1, | ||||||||||||||||||||||||||||
| 52 | message => "YAML backend configured successfully", | ||||||||||||||||||||||||||||
| 53 | config => { | ||||||||||||||||||||||||||||
| 54 | storage_dir => $storage_dir, | ||||||||||||||||||||||||||||
| 55 | fields => $setup_config->{fields} || [], | ||||||||||||||||||||||||||||
| 56 | field_definitions => $setup_config->{field_definitions}, | ||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||
| 58 | 19 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$setup_config->{'fields'} || []
MC/DC0%0/1
$setup_config->{'fields'} || []
$setup_config->{'fields'}
Truth table50%1/2
A
A= $setup_config->{'fields'}
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # ============================================================================== | ||||||||||||||||||||||||||||
| 62 | # Constructor - Runtime instantiation (called by Users->new) | ||||||||||||||||||||||||||||
| 63 | # ============================================================================== | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 20 | my ($class, $runtime_config) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Extract parameters from saved config (no validation needed) | ||||||||||||||||||||||||||||
| 69 | 20 | my $storage_dir = $runtime_config->{storage_dir}; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | return bless { | ||||||||||||||||||||||||||||
| 72 | storage_dir => $storage_dir, | ||||||||||||||||||||||||||||
| 73 | fields => $runtime_config->{fields} || [], | ||||||||||||||||||||||||||||
| 74 | field_definitions => $runtime_config->{field_definitions} || {}, | ||||||||||||||||||||||||||||
| 75 | 20 | ▶ | }, $class; | ||||||||||||||||||||||||||
|
Condition50%2/4
$runtime_config->{'fields'} || []
$runtime_config->{'field_definitions'} || {}
MC/DC0%0/1
$runtime_config->{'fields'} || []
$runtime_config->{'fields'}
MC/DC0%0/1
$runtime_config->{'field_definitions'} || {}
$runtime_config->{'field_definitions'}
Truth table50%1/2
A
A= $runtime_config->{'fields'}
Truth table50%1/2
A
A= $runtime_config->{'field_definitions'}
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Report backend configuration (for debugging/info) | ||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub config { | ||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | return { | ||||||||||||||||||||||||||||
| 83 | storage_dir => $self->{storage_dir}, | ||||||||||||||||||||||||||||
| 84 | fields => $self->{fields}, | ||||||||||||||||||||||||||||
| 85 | field_definitions => $self->{field_definitions}, | ||||||||||||||||||||||||||||
| 86 | 1 | }; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # Get user file path | ||||||||||||||||||||||||||||
| 90 | 113 | ▶ | sub _get_user_file { | ||||||||||||||||||||||||||
|
Subroutine
_get_user_file: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | 113 | my ($self, $user_id) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 113 | return File::Spec->catfile($self->{storage_dir}, "$user_id.yaml"); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # Archive existing user data (internal method, called by configure) | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | sub _archive_user_data { | ||||||||||||||||||||||||||
|
Subroutine
_archive_user_data: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||
| 98 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # Generate timestamp for archive directory name | ||||||||||||||||||||||||||||
| 101 | 1 | my $timestamp = $self->archive_timestamp(); | |||||||||||||||||||||||||||
| 102 | 1 | my $archive_dir = "$self->{storage_dir}/users_$timestamp"; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Create archive directory | ||||||||||||||||||||||||||||
| 105 | 1 | ▶ | unless (mkdir $archive_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | return { | ||||||||||||||||||||||||||||
| 107 | 0 | success => 0, | |||||||||||||||||||||||||||
| 108 | message => "Failed to create archive directory: $!" | ||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Find and move all .yaml files | ||||||||||||||||||||||||||||
| 113 | 1 | my $dh; | |||||||||||||||||||||||||||
| 114 | 1 | ▶ | unless (opendir($dh, $self->{storage_dir})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | return { | ||||||||||||||||||||||||||||
| 116 | 0 | success => 0, | |||||||||||||||||||||||||||
| 117 | message => "Failed to open storage directory: $!" | ||||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | my @yaml_files = grep { /\.yaml$/ && -f "$self->{storage_dir}/$_" } readdir $dh; | ||||||||||||||||||||||||||
|
Condition66%2/3
/\.yaml$/u && -f "$self->{'storage_dir'}/$_"
MC/DC50%1/2
/\.yaml$/u && -f "$self->{'storage_dir'}/$_"
/\.yaml$/u
-f "$self->{'storage_dir'}/$_"
Truth table66%2/3
A && B
A= /\.yaml$/uB= -f "$self->{'storage_dir'}/$_"
| |||||||||||||||||||||||||||||
| 122 | 1 | closedir $dh; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | foreach my $file (@yaml_files) { | |||||||||||||||||||||||||||
| 125 | 2 | my $old_path = "$self->{storage_dir}/$file"; | |||||||||||||||||||||||||||
| 126 | 2 | my $new_path = "$archive_dir/$file"; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | ▶ | unless (rename $old_path, $new_path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | return { | ||||||||||||||||||||||||||||
| 130 | 0 | success => 0, | |||||||||||||||||||||||||||
| 131 | message => "Failed to archive YAML file '$file': $!" | ||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | return { success => 1 }; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # Add bare record with user_id, moniker, defaults, and null_values from Users.pm | ||||||||||||||||||||||||||||
| 140 | 27 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 27 | my ($self, $user_id, $initial_record) = @_; | |||||||||||||||||||||||||||
| 142 | 27 | ▶ | return { success => 0, message => "Add Record failed: missing user_id" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | unless $user_id; | ||||||||||||||||||||||||||||
| 144 | 27 | ▶ | return { success => 0, message => "Add Record failed: missing initial record" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | unless $initial_record; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 27 | my %record = $initial_record->%*; | |||||||||||||||||||||||||||
| 148 | 27 | $record{created_date} = $self->current_timestamp(); | |||||||||||||||||||||||||||
| 149 | # Add last_mod_date timestamp | ||||||||||||||||||||||||||||
| 150 | 27 | $record{last_mod_date} = $self->current_timestamp(); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 27 | my $user_file = $self->_get_user_file($user_id); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 27 | eval { | |||||||||||||||||||||||||||
| 155 | 27 | YAML::Tiny::DumpFile($user_file, \%record); | |||||||||||||||||||||||||||
| 156 | }; | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 27 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | return { success => 0, message => "Failed to create initial user record: $@" }; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 27 | return { success => 1, message => "Initial record created for user '$user_id'" }; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # Fetch user by ID | ||||||||||||||||||||||||||||
| 166 | 54 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 54 | my ($self, $user_id) = @_; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 54 | my $user_file = $self->_get_user_file($user_id); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | return { | ||||||||||||||||||||||||||||
| 172 | 54 | ▶ | success => 0, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | data => '', | ||||||||||||||||||||||||||||
| 174 | message => "User '$user_id' not found" | ||||||||||||||||||||||||||||
| 175 | } unless -f $user_file; | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 22 | my $user_data; | |||||||||||||||||||||||||||
| 178 | 22 | eval { | |||||||||||||||||||||||||||
| 179 | 22 | $user_data = YAML::Tiny::LoadFile($user_file); | |||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 22 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | return { | ||||||||||||||||||||||||||||
| 184 | 0 | success => 0, | |||||||||||||||||||||||||||
| 185 | data => '', | ||||||||||||||||||||||||||||
| 186 | message => "Failed to load user data: $@" | ||||||||||||||||||||||||||||
| 187 | }; | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | return { | ||||||||||||||||||||||||||||
| 191 | 22 | success => 1, | |||||||||||||||||||||||||||
| 192 | data => $user_data, | ||||||||||||||||||||||||||||
| 193 | message => '' | ||||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # Update user | ||||||||||||||||||||||||||||
| 198 | 30 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 30 | my ($self, $user_id, $updates) = @_; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # Remove readonly fields from updates | ||||||||||||||||||||||||||||
| 202 | 30 | my %readonly = map { $_ => 1 } qw(user_id created_date last_mod_date); | |||||||||||||||||||||||||||
| 203 | 30 | delete $updates->{$_} for keys %readonly; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # Add last_mod_date timestamp | ||||||||||||||||||||||||||||
| 206 | 30 | $updates->{last_mod_date} = $self->current_timestamp(); | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 30 | my $user_file = $self->_get_user_file($user_id); | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 30 | ▶ | return { success => 0, message => "User '$user_id' not found" } unless -f $user_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | # Load existing data | ||||||||||||||||||||||||||||
| 213 | 30 | my $user_data; | |||||||||||||||||||||||||||
| 214 | 30 | eval { | |||||||||||||||||||||||||||
| 215 | 30 | $user_data = YAML::Tiny::LoadFile($user_file); | |||||||||||||||||||||||||||
| 216 | }; | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 30 | ▶ | return { success => 0, message => "Failed to load user data: $@" } if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # Apply updates | ||||||||||||||||||||||||||||
| 221 | 30 | foreach my $field (keys %$updates) { | |||||||||||||||||||||||||||
| 222 | 75 | $user_data->{$field} = $updates->{$field}; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # Save back | ||||||||||||||||||||||||||||
| 226 | 30 | eval { | |||||||||||||||||||||||||||
| 227 | 30 | YAML::Tiny::DumpFile($user_file, $user_data); | |||||||||||||||||||||||||||
| 228 | }; | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 30 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | return { success => 0, message => "Failed to update user file: $@" }; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 30 | return { success => 1, message => "User '$user_id' updated" }; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | # List users with filters | ||||||||||||||||||||||||||||
| 238 | 7 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=22 SCAR=34.8
Pod
documented
| |||||||||||||||||||||||||||||
| 239 | 7 | my ($self, $filters, $options) = @_; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # Read all YAML files | ||||||||||||||||||||||||||||
| 242 | 7 | ▶ | opendir my $dh, $self->{storage_dir} or return { data => [], total_count => 0 }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 7 | my @files = grep { /\.yaml$/ } readdir $dh; | |||||||||||||||||||||||||||
| 244 | 7 | closedir $dh; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 7 | my @users; | |||||||||||||||||||||||||||
| 247 | 7 | foreach my $file (@files) { | |||||||||||||||||||||||||||
| 248 | 21 | my $user_file = File::Spec->catfile($self->{storage_dir}, $file); | |||||||||||||||||||||||||||
| 249 | 21 | my $user_data; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 21 | eval { | |||||||||||||||||||||||||||
| 252 | 21 | $user_data = YAML::Tiny::LoadFile($user_file); | |||||||||||||||||||||||||||
| 253 | }; | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 21 | ▶ | next if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | # Apply DSL filters | ||||||||||||||||||||||||||||
| 258 | 14 | my $match = 1; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 14 | ▶ | if (ref $filters eq 'HASH' && exists $filters->{or_groups}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $filters eq "HASH" and exists $filters->{"or_groups"}
MC/DC50%1/2
ref $filters eq "HASH" and exists $filters->{"or_groups"}
ref $filters eq "HASH"
exists $filters->{"or_groups"}
Truth table66%2/3
A and B
A= ref $filters eq "HASH"B= exists $filters->{"or_groups"}
| |||||||||||||||||||||||||||||
| 261 | 6 | $match = 0; # Start with no match, need at least one OR group to match | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 6 | foreach my $and_group (@{$filters->{or_groups}}) { | |||||||||||||||||||||||||||
| 264 | 6 | my $group_match = 1; # All conditions in this AND group must match | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 6 | foreach my $condition (@$and_group) { | |||||||||||||||||||||||||||
| 267 | 6 | my ($field, $op, $value) = ($condition->{field}, $condition->{op}, $condition->{value}); | |||||||||||||||||||||||||||
| 268 | 6 | ▶ | my $user_value = $user_data->{$field} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$user_data->{$field} || ''
MC/DC0%0/1
$user_data->{$field} || ''
$user_data->{$field}
Truth table50%1/2
A
A= $user_data->{$field}
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 6 | ▶ | if ($op eq '=') { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 271 | 3 | ▶ | $group_match = 0 unless $user_value eq $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | } elsif ($op eq ':') { | ||||||||||||||||||||||||||||
| 273 | 3 | ▶ | $group_match = 0 unless $user_value =~ /\Q$value\E/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | } elsif ($op eq '!') { | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $group_match = 0 if $user_value =~ /\Q$value\E/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | } elsif ($op eq '>') { | ||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $group_match = 0 unless $user_value gt $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | } elsif ($op eq '<') { | ||||||||||||||||||||||||||||
| 279 | 0 | ▶ | $group_match = 0 unless $user_value lt $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 6 | ▶ | $match = 1 if $group_match; # At least one OR group matched | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 6 | ▶ | last if $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 14 | ▶ | push @users, $user_data if $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | return { | ||||||||||||||||||||||||||||
| 292 | 7 | data => \@users, | |||||||||||||||||||||||||||
| 293 | total_count => scalar @users, | ||||||||||||||||||||||||||||
| 294 | }; | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | # Delete user | ||||||||||||||||||||||||||||
| 298 | 2 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 299 | 2 | my ($self, $user_id) = @_; | |||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 2 | my $user_file = $self->_get_user_file($user_id); | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 2 | ▶ | return { success => 0, message => "User '$user_id' not found" } unless -f $user_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 2 | ▶ | unlink $user_file or return { success => 0, message => "Failed to delete user file: $!" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 2 | return { success => 1, message => "User '$user_id' deleted" }; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # Cleanup | ||||||||||||||||||||||||||||
| 311 | 20 | ▶ | sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 312 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 313 | # No resources to clean up for YAML backend | ||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 6 | 1; | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | __END__ | ||||||||||||||||||||||||||||