Coerce-Types-Standard
view release on metacpan or search on metacpan
lib/Coerce/Types/Standard.pm view on Meta::CPAN
$uri->query_form($queryForm) if $queryForm;
return $uri;
},
abuse_parent => \&_uri_change,
abuse_constraint => \&_uri_constraint,
abuse => \&_uri
});
sub _uri_change {
my $hide = shift;
return scalar $meta->Str if $hide =~ m/^escape|unescape|schema|host|path|query_string|fragment$/;
return scalar $meta->HashRef;
}
sub _uri_constraint {
my $hide = sprintf "constraint_uri_%s", shift;
\&$hide;
}
# I don't know why, just don't ask
sub constraint_uri_schema {
lib/Coerce/Types/Standard.pm view on Meta::CPAN
sub constraint_uri_path {
$_[0] =~ m/$path/;
$2 || $4 || $6 || $7 ? 0 : 1;
}
sub constraint_uri_query_string {
$_[0] =~ m/$path/;
$2 || $4 || $5 || $7 ? 0 : 1;
}
sub constraint_uri_fragment {
$_[0] =~ m/$path/;
$2 || $4 || $5 || $6 ? 0 : 1;
}
sub constraint_uri_query_form {
ref $_[0] eq 'HASH' ? 1 : 0;
}
sub constraint_uri_escape {
$_[0] =~ m/($esc)(?!$unesc)/ ? 0 : 1;
lib/Coerce/Types/Standard.pm view on Meta::CPAN
sub uri_path {
$_[0] =~ m/$path/;
return $5;
}
sub uri_query_string {
$_[0] =~ m/$path/;
return uri_unescape($6);
}
sub uri_fragment {
$_[0] =~ m/$path/;
return $7;
}
sub uri_query_form {
$_[0] =~ m/$path/;
my $query_string = uri_unescape($6);
$query_string =~ s,^\?,,;
return +{
split '=', $query_string
lib/Coerce/Types/Standard.pm view on Meta::CPAN
=item query_form
Extract the query form from the given url.
URI->by('path')->coerce('https://example.lnation.org?okay=s');
*-*-*-*-*-*-*
{
okay => s
}
=item fragment
Extract the fragment from the given url.
URI->by('fragment')->coerce('https://example.lnation.org#okays');
*-*-*-*-*-*-*
# okays
=item escape
URI escape the given string.
URI->by('escape')->coerce('!$^@$%');
*-*-*-*-*-*-*
%21%24%5E%40%24%25
use Coerce::Types::Standard qw/URI/;
use MooX::LazierAttributes;
attributes (
[qw/url schema_url autoescape_url queryForm/] => [URI, { coe }],
'schema' => [URI->by('schema'), {coe}],
'host' => [URI->by('host'), {coe}],
'path' => [URI->by('path'), {coe}],
'queryString', [URI->by('query_string'), {coe}],
'queryForms', [URI->by('query_form'), {coe}],
'frag', [URI->by('fragment'), {coe}],
'escape' => [URI->by('escape'), {coe}],
'unescape' => [URI->by('unescape'), {coe}],
);
}
use Have::Fun;
my $thing = Have::Fun->new(
url => q|example.lnation.com|,
schema_url => [q|example.lnation.com|, q|https|],
autoescape_url => q|https://example.lnation.com?one= a b c&two=1!2£3|,
queryForm => [q|https://example.lnation.com|, { a => 'b' }],
schema => q|https://example.lnation.com/okays?one=two#yep|,
host => q|https://example.lnation.com/okays?one=two#yep|,
path => q|https://example.lnation.com/okays?one=two#yep|,
frag => q|https://example.lnation.com/okays?one=two#yep|,
queryString => q|https://example.lnation.com/okays?one=two#yep|,
queryForms => q|https://example.lnation.com/okays?one=two#yep|,
escape => q|!$^@$%|,
unescape => q|%21%24%5E%40%24%25|,
);
is($thing->url->as_string, 'example.lnation.com');
# whys
is(sprintf('https://%s', $thing->schema_url->as_string), 'https://example.lnation.com');
is($thing->autoescape_url->as_string, 'https://example.lnation.com?one=%20a%20b%20c&two=1!2%C2%A33');
is($thing->queryForm->as_string, 'https://example.lnation.com?a=b');
is($thing->schema, 'https');
is($thing->host, 'example.lnation.com');
is($thing->path, '/okays');
is($thing->queryString, '?one=two');
is($thing->frag, '#yep');
is_deeply($thing->queryForms, { one => 'two' });
is($thing->escape, '%21%24%5E%40%24%25');
is($thing->unescape, '!$^@$%');
done_testing();
( run in 1.514 second using v1.01-cache-2.11-cpan-364913b4093 )