blib/lib/Uniform/HTMX/Mojolicious.pm

filter: Statementstmt 100% 33 / 33 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 88.8% 48 / 54 CC 7 SCAR 11.7
CC
7
Cov
91%
new
5.1
apply
3.0
BEGIN
1.0
CRAP 3.2
↑ Summary
1 package Uniform::HTMX::Mojolicious;
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 a Mojolicious Controller object ($c)
11 sub new {
12 2 ▶ my ($class, $c) = @_;
Subroutine new: called CC=5 SCAR=16.3
Pod documented
13  
14 2 ▶ croak "Mojolicious context must be a blessed object reference" unless ref($c);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 1 1 2
15 1 ▶ croak "Not a valid Mojolicious controller execution context"
Branch: 1 branch
BranchTrueFalseTotal
unless $c->can("req") and $c->req->can("headers") 0 1 1
Condition33%1/3
$c->can("req") and $c->req->can("headers")
!ll&&!rl&&r
001
MC/DC0%0/2
$c->can("req") and $c->req->can("headers")
$c->can("req") $c->req->can("headers")
Truth table33%1/3
A and B
A= $c->can("req")B= $c->req->can("headers")
ABresult
0X0
100
111
16 unless $c->can('req') && $c->req->can('headers');
17  
18 1 my $self = bless {
19 in => {},
20 out => {},
21 _ctx => $c,
22 }, $class;
23  
24 # Extract headers out of Mojo::Headers
25 1 my %raw;
26 1 my $headers = $c->req->headers;
27 1 foreach my $name (@{ $headers->names }) {
28 2 $raw{$name} = $headers->header($name);
29 }
30  
31 # Execute your core baseline normalization utility inherited from Uniform::HTMX
32 1 $self->{in} = $self->_normalize_headers(\%raw);
33 1 return $self;
34 }
35  
36 # Flushes outbound HTMX modifications directly onto Mojolicious's active response stream
37 sub apply {
38 1 ▶ my ($self) = @_;
Subroutine apply: called CC=3 SCAR=11.0
Pod documented
39 1 ▶ return $self unless ref($self->{out}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"out"} eq "HASH" 0 1 1
40  
41 1 my %outbound = %{ $self->{out} };
42 1 my $res_headers = $self->{_ctx}->res->headers;
43  
44 1 ▶ while (my ($k, $v) = each %outbound) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %outbound) 2 1 3
45 2 $res_headers->header($k => "$v");
46 }
47  
48 1 return $self;
49 }
50  
51 2 1;
52  
53 __END__
↑ Summary