Web-ComposableRequest
view release on metacpan or search on metacpan
lib/Web/ComposableRequest.pm view on Meta::CPAN
$attr->{env } = pop @args if @args and is_hashref $args[-1];
$attr->{params} = pop @args if @args and is_hashref $args[-1];
my $query = $attr->{env}->{'Web::Dispatch::ParamParser.unpacked_query'};
$attr->{params} = $query if $query;
for my $arg (grep { defined && length } @args) {
if (blessed $arg) { $attr->{upload} = $arg }
else {
push @{ $attr->{args} //= [] }, map { trim $_ } split m{ / }mx, $arg;
}
}
return $request_class->new($self->buildargs->($self, $attr));
}
1;
__END__
lib/Web/ComposableRequest/Base.pm view on Meta::CPAN
has 'body' => is => 'lazy', isa => Object, builder => $_build_body;
has 'content_length' => is => 'lazy', isa => PositiveInt,
builder => sub { $_[ 0 ]->_env->{ 'CONTENT_LENGTH' } // 0 };
has 'content_type' => is => 'lazy', isa => SimpleStr,
builder => sub { $_[ 0 ]->_env->{ 'CONTENT_TYPE' } // NUL };
has 'host' => is => 'lazy', isa => NonEmptySimpleStr,
builder => sub { (split m{ : }mx, $_[ 0 ]->hostport)[ 0 ] };
has 'hostport' => is => 'lazy', isa => NonEmptySimpleStr,
builder => sub { $_[ 0 ]->_env->{ 'HTTP_HOST' } // 'localhost' };
has 'method' => is => 'lazy', isa => SimpleStr,
builder => sub { lc( $_[ 0 ]->_env->{ 'REQUEST_METHOD' } // NUL )};
has 'path' => is => 'lazy', isa => SimpleStr, builder => sub {
my $v = $_[ 0 ]->_env->{ 'PATH_INFO' } // '/';
$v =~ s{ \A / }{}mx; $v =~ s{ \? .* \z }{}mx; $v };
lib/Web/ComposableRequest/Role/Cookie.pm view on Meta::CPAN
requires qw( _config _env );
add_config_role __PACKAGE__.'::Config';
my $_decode = sub {
my ($cookies, $prefix, $name) = @_; my $cname = "${prefix}_${name}";
my $attr = {}; ($name and exists $cookies->{ $cname }) or return $attr;
for (split m{ \+ }mx, $cookies->{ $cname }->value) {
my ($k, $v) = split m{ ~ }mx, $_; $k and $attr->{ $k } = $v;
}
return $attr;
};
has 'cookies' => is => 'lazy', isa => HashRef, builder => sub {
my %v = CGI::Simple::Cookie->parse( $_[ 0 ]->_env->{ 'HTTP_COOKIE' } ); \%v;
};
sub get_cookie_hash {
lib/Web/ComposableRequest/Role/L10N.pm view on Meta::CPAN
return $conf->locale;
};
my $_build_locales = sub {
my $self = shift;
my $lang = $self->_env->{ 'HTTP_ACCEPT_LANGUAGE' } // NUL;
return [ map { s{ _ \z }{}mx; $_ }
map { join '_', $_->[ 0 ], uc( $_->[ 1 ] // NUL ) }
map { [ split m{ - }mx, $_ ] }
map { ( split m{ ; }mx, $_ )[ 0 ] }
split m{ , }mx, lc $lang ];
};
my $_build_localiser = sub {
return sub {
my ($key, $args) = @_;
defined $key or return; $key = "${key}"; chomp $key; $args //= {};
my $text = $key;
lib/Web/ComposableRequest/Role/Static.pm view on Meta::CPAN
use Web::ComposableRequest::Constants qw( FALSE NUL TRUE );
use Web::ComposableRequest::Util qw( first_char is_arrayref
is_hashref new_uri );
use Moo::Role;
requires qw( locale path query_params scheme _base );
around '_build__base' => sub {
my ($orig, $self) = @_; $self->mode eq 'static' or return $orig->( $self );
my $count = () = split m{ / }mx, $self->path, -1;
return '../' x $count;
};
around '_build_uri' => sub {
my ($orig, $self) = @_; $self->mode eq 'static' or return $orig->( $self );
my $path = $self->_base.$self->locale.'/'.$self->path.'.html';
return new_uri $self->scheme, $path;
lib/Web/ComposableRequest/Util.pm view on Meta::CPAN
$param->{ decode( $enc, $k ) }
= is_arrayref( $v ) ? [ map { decode( $enc, $_ ) } @{ $v } ]
: decode( $enc, $v );
}
return;
}
sub extract_lang ($) {
my $v = shift; return $v ? (split m{ _ }mx, $v)[ 0 ] : LANG;
}
sub first_char ($) {
return substr $_[ 0 ], 0, 1;
}
sub is_arrayref (;$) {
return $_[ 0 ] && ref $_[ 0 ] eq 'ARRAY' ? 1 : 0;
}
( run in 0.558 second using v1.01-cache-2.11-cpan-71847e10f99 )