URL::XS - Parsing URLs with zero-copy and no mallocs
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.
use URL::XS (parse_url split_url_path parse_url_query); my $url = 'https://peter:bro@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' => 'https', # 'username' => 'peter', # 'password' => 'bro', # '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' # };
Parse absolute URL string:
scheme ":" ["//"] [user ":" passwd "@"] host [":" port] ["/"] [path] ["?" query] ["#" fragment]
Returns hasref with parsed url data.
Split relative url path (with optionally separator) with '/' path separator by default.
Returns arrayeref with splitted relative url path.
Parse URL query part (with optionally separator). Symbol '&' is a default query separator.
Returns hashref with parsed query.
libyuarel
Peter P. Neuromantic <p.brovchenko@protonmail.com>
The MIT License (MIT)
Copyright (c) 2021 Peter P. Neuromantic <p.brovchenko@protonmail.com>. All rights reserved.
See LICENSE file for more information.
To install URL::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm URL::XS
CPAN shell
perl -MCPAN -e shell install URL::XS
For more information on module installation, please visit the detailed CPAN module installation guide.