blib/lib/Uniform/HTMX/PAGI.pm

filter: Statementstmt 100% 34 / 34 Branchbran 60.0% 6 / 10 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 79.1% 53 / 67 CC 10 SCAR 19.3
CC
10
Cov
83%
new
10.5
apply
2.0
BEGIN
1.0
CRAP 6.9
↑ Summary
1 package Uniform::HTMX::PAGI;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent 'Uniform::HTMX';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.00';
9  
10 # Constructor: Explicitly expects an asynchronous PAGI HTTP connection scope hash reference
11 sub new {
12 2 ▶ my ($class, $scope) = @_;
Subroutine new: called CC=9 SCAR=23.5
Pod documented
13  
14 2 ▶ croak "PAGI scope must be a HASH reference" unless ref($scope) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $scope eq "HASH" 0 2 2
15 croak "Not a valid PAGI HTTP connection scope"
16 2 ▶ unless (defined $scope->{type} && $scope->{type} eq 'http');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scope->{"type"} and $scope->{"type"} eq "http" 1 1 2
Condition66%2/3
defined $scope->{"type"} and $scope->{"type"} eq "http"
!ll&&!rl&&r
011
MC/DC50%1/2
defined $scope->{"type"} and $scope->{"type"} eq "http"
defined $scope->{"type"} $scope->{"type"} eq "http"
Truth table66%2/3
A and B
A= defined $scope->{"type"}B= $scope->{"type"} eq "http"
ABresult
0X0
100
111
17  
18 1 my $self = bless {
19 in => {},
20 out => {},
21 _ctx => $scope,
22 }, $class;
23  
24 # Extract PAGI nested array of array headers: [ ['hx-request', 'true'], ['hx-target', 'grid'] ]
25 1 my %raw;
26 1 ▶ if ($scope->{headers} && ref($scope->{headers}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->{"headers"} and ref $scope->{"headers"} eq "ARRAY") 1 0 1
Condition33%1/3
$scope->{"headers"} and ref $scope->{"headers"} eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
$scope->{"headers"} and ref $scope->{"headers"} eq "ARRAY"
$scope->{"headers"} ref $scope->{"headers"} eq "ARRAY"
Truth table33%1/3
A and B
A= $scope->{"headers"}B= ref $scope->{"headers"} eq "ARRAY"
ABresult
0X0
100
111
27 1 foreach my $pair (@{ $scope->{headers} }) {
28 4 ▶ next unless ref($pair) eq 'ARRAY' && defined $pair->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pair eq "ARRAY" and defined $pair->[0] 0 4 4
Condition33%1/3
ref $pair eq "ARRAY" and defined $pair->[0]
!ll&&!rl&&r
004
MC/DC0%0/2
ref $pair eq "ARRAY" and defined $pair->[0]
ref $pair eq "ARRAY" defined $pair->[0]
Truth table33%1/3
A and B
A= ref $pair eq "ARRAY"B= defined $pair->[0]
ABresult
0X0
100
111
29  
30 # Group identical keys inside array references so your core engine's
31 # multi-value reduction filter can safely isolate the winning scalar
32 4 push @{ $raw{$pair->[0]} }, $pair->[1];
33 }
34 }
35  
36 # Pass the isolated dataset directly to your central Uniform normalization routine
37 1 $self->{in} = $self->_normalize_headers(\%raw);
38 1 return $self;
39 }
40  
41 # Flushes outbound changes asynchronously back down into the target scope reference block
42 sub apply {
43 1 ▶ my ($self) = @_;
Subroutine apply: called CC=2 SCAR=7.0
Pod documented
44 1 ▶ return $self unless ref($self->{out}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"out"} eq "HASH" 0 1 1
45  
46 1 my %outbound = %{ $self->{out} };
47  
48 # Transform flat outbound instructions into the explicit PAGI array-of-arrays context format
49 $self->{_ctx}->{'htmx.outbound'} = [
50 1 map { [ $_ => "$outbound{$_}" ] } keys %outbound
51 ];
52  
53 1 return $self;
54 }
55  
56 2 1;
57  
58 __END__
↑ Summary