| 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
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | croak "Not a valid Mojolicious controller execution context" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->can("req") and $c->req->can("headers")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 2 | $res_headers->header($k => "$v"); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | return $self; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||