NAME
URL::XS - Parsing URLs with zero-copy and no mallocs
DESCRIPTION
This is a perl binding to libyaurel (simple C library for parsing URLs with zero-copy and no mallocs). Might parse: url, url paths and url queries.
SYNOPSIS
use URL::XS (parse_url split_url_path parse_url_query);
my $url = 'http://localhost:8989/some/path/to/resource?q1=yes&q2=no&q3=maybe#frag=1';
# Basic parse
my $parsed_url = parse_url($url);
say Dumper $parsed_url;
# $VAR1 = {
# 'scheme' => 'http',
# 'host' => 'localhost',
# 'port' => 8989,
# 'path' => 'some/path/to/resource',
# 'query' => 'q1=yes&q2=no&q3=maybe',
# 'fragment' => 'frag=1'
# };
# Parse relative url path
my $url_path = split_url_path($parsed_url->{path});
say Dumper $url_path;
# $VAR1 = [ 'some', 'path', 'to', 'resource' ];
# Parse url query
my $url_queries = parse_url_query($parsed_url->{query});
say Dumper $url_queries;
# $VAR1 = {
# 'q1' => 'yes',
# 'q2' => 'no',
# 'q3' => 'maybe'
# };
FUNCTIONS
parse_url($url)
Prse absolute URL string:
scheme ":" ["//"] [user ":" passd "@"] host [":" port] ["/"] [path] ["?" query] ["#" fragment]
Returns hasref with parsed url data.
split_url_path($url_path, [$split_separator])
Split relative url path (with optionally separator) with '/' path separatoe by default.
Returns arrayeref with splitted relative url path.
parse_url_query($url_query, [$query_separator])
Parse URL query part (with optionally separator). Symbol '&' is a default query separator.
Returns hashref with parsed query.
SEE ALSO
AUTHOR
Peter P. Neuromantic <p.brovchenko@protonmail.com>
LICENSE AND COPYRIGHT
The MIT License (MIT)
Copyright (c) 2021 Peter P. Neuromantic <p.brovchenko@protonmail.com>. All rights reserved.
See LICENSE file for more information.