| 1 | package Web::ComposableRequest; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use version; our $VERSION = qv( sprintf '0.22.%d', q$Rev: 1 $ =~ /\d+/gmx ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Web::ComposableRequest::Constants qw( NUL ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Unexpected::Types qw( CodeRef HashRef NonEmptySimpleStr | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | Object Undef ); | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Web::ComposableRequest::Util qw( first_char is_hashref | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | list_config_roles merge_attributes | ||||||||||||||||||||||||||||
| 12 | 1 | trim ); | |||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Web::ComposableRequest::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Web::ComposableRequest::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Moo::Role (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has 'buildargs' => | ||||||||||||||||||||||||||||
| 20 | is => 'lazy', | ||||||||||||||||||||||||||||
| 21 | isa => CodeRef, | ||||||||||||||||||||||||||||
| 22 | 2 | ▶ | default => sub { sub { return $_[1] } }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | has 'config' => | ||||||||||||||||||||||||||||
| 25 | is => 'lazy', | ||||||||||||||||||||||||||||
| 26 | isa => Object, | ||||||||||||||||||||||||||||
| 27 | 2 | ▶ | default => sub { $_[0]->config_class->new($_[0]->config_attr) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | init_arg => undef; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | has 'config_attr' => | |||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||
| 32 | isa => HashRef|Object|Undef, | ||||||||||||||||||||||||||||
| 33 | init_arg => 'config'; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has 'config_class' => | ||||||||||||||||||||||||||||
| 36 | is => 'lazy', | ||||||||||||||||||||||||||||
| 37 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 39 | 2 | my $base = __PACKAGE__ . '::Config'; | |||||||||||||||||||||||||||
| 40 | 2 | my @roles = list_config_roles; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | return $base unless @roles > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | return Moo::Role->create_class_with_roles($base, @roles); | |||||||||||||||||||||||||||
| 45 | 1 | }; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | has 'request_class' => | ||||||||||||||||||||||||||||
| 48 | is => 'lazy', | ||||||||||||||||||||||||||||
| 49 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 50 | 2 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 51 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 2 | my $base = __PACKAGE__ . '::Base'; | |||||||||||||||||||||||||||
| 53 | 2 | ▶ | my $conf = $self->config_attr or return $base; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 2 | my $dflt = { request_class => $base, request_roles => [] }; | |||||||||||||||||||||||||||
| 55 | 2 | my $attr = {}; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | merge_attributes $attr, $conf, $dflt, [keys %{$dflt}]; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | my @roles = @{$attr->{request_roles}}; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | return $attr->{request_class} unless @roles > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | @roles = map { (first_char $_ eq '+') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | ? substr $_, 1 : __PACKAGE__ . "::Role::${_}" } @roles; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | return Moo::Role->create_class_with_roles($attr->{request_class}, @roles); | |||||||||||||||||||||||||||
| 67 | 1 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 7 | ▶ | sub new_from_simple_request { | ||||||||||||||||||||||||||
|
Subroutine
new_from_simple_request: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 7 | my ($self, $opts, @args) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 7 | ▶ | my $attr = { %{ $opts // {} } }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts // {}
MC/DC0%0/1
$opts // {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||
| 73 | 7 | my $request_class = $self->request_class; # Trigger role application | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 7 | $attr->{config} = $self->config; # Composed after request_class | |||||||||||||||||||||||||||
| 76 | 7 | ▶ | $attr->{env } = pop @args if @args and is_hashref $args[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args and &is_hashref($args[-1])
MC/DC50%1/2
@args and &is_hashref($args[-1])
@args
&is_hashref($args[-1])
Truth table66%2/3
A and B
A= @argsB= &is_hashref($args[-1])
| |||||||||||||||||||||||||||||
| 77 | 7 | ▶ | $attr->{params} = pop @args if @args and is_hashref $args[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args and &is_hashref($args[-1])
MC/DC50%1/2
@args and &is_hashref($args[-1])
@args
&is_hashref($args[-1])
Truth table66%2/3
A and B
A= @argsB= &is_hashref($args[-1])
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 7 | my $query = $attr->{env}->{'Web::Dispatch::ParamParser.unpacked_query'}; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 7 | ▶ | $attr->{params} = $query if $query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 7 | ▶ | for my $arg (grep { defined && length } @args) { | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $_ && length $_
MC/DC100%2/2
defined $_ && length $_
defined $_
length $_
Truth table100%3/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | if (blessed $arg) { $attr->{upload} = $arg } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||
| 86 | 2 | ▶ | push @{ $attr->{args} //= [] }, map { trim $_ } split m{ / }mx, $arg; | ||||||||||||||||||||||||||
|
Condition50%1/2
$attr->{"args"} //= []
MC/DC0%0/1
$attr->{"args"} //= []
$attr->{"args"}
Truth table50%1/2
A
A= $attr->{"args"}
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 7 | return $request_class->new($self->buildargs->($self, $attr)); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||