blib/lib/Uniform/HTMX/PSGI.pm

filter: Statementstmt 100% 29 / 29 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 97.8% 46 / 47 CC 6 SCAR 11.0
CC
6
Cov
97%
apply
5.0
new
2.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package Uniform::HTMX::PSGI;
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.01';
9  
10 # Constructor: Expects a standard PSGI %env Hash reference
11 sub new {
12 2 ▶ my ($class, $env) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
13  
14 2 ▶ croak "PSGI environment context must be a HASH reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $env eq "HASH" 1 1 2
15 unless ref($env) eq 'HASH';
16  
17 1 my $self = bless {
18 in => {},
19 out => {},
20 _ctx => $env,
21 }, $class;
22  
23 # Pass the raw %env directly to your core version 1.01 normalization engine.
24 # Your core automatically strips "HTTP_" prefixes and maps underscores to dashes!
25 1 $self->{in} = $self->_normalize_headers($env);
26  
27 1 return $self;
28 }
29  
30 # Flushes outbound HTMX instructions securely back into the PSGI lifecycle environment
31 sub apply {
32 2 ▶ my ($self, $response_object) = @_;
Subroutine apply: called CC=5 SCAR=16.1
Pod documented
33 2 ▶ return $self unless ref($self->{out}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"out"} eq "HASH" 0 2 2
34  
35 2 my %outbound = %{ $self->{out} };
36  
37 # Strategy A: If a Plack::Response object is explicitly passed, map headers directly
38 2 ▶ if (eval { $response_object && $response_object->can('headers') }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { $response_object and $response_object->can('headers') } }) { } 1 1 2
$response_object and $response_object->can("headers") 1 1 2
39 1 ▶ while (my ($k, $v) = each %outbound) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %outbound) 2 1 3
40 2 $response_object->headers->header($k => $v);
41 }
42 }
43 # Strategy B: Fall back to stashing them inside the standard $env hash slot
44 else {
45 1 $self->{_ctx}->{'htmx.outbound'} = \%outbound;
46 }
47  
48 2 return $self;
49 }
50  
51 2 1;
52  
53 __END__
↑ Summary