| 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
| |||||||||||||||||||||||||||||
| 15 | croak "Not a valid PAGI HTTP connection scope" | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | unless (defined $scope->{type} && $scope->{type} eq 'http'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $scope->{"type"} and $scope->{"type"} eq "http"
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"
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$scope->{"headers"} and ref $scope->{"headers"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 27 | 1 | foreach my $pair (@{ $scope->{headers} }) { | |||||||||||||||||||||||||||
| 28 | 4 | ▶ | next unless ref($pair) eq 'ARRAY' && defined $pair->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $pair eq "ARRAY" and defined $pair->[0]
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]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||