URI::FromHash(3pm)

πŸ“¦
version 0.05 Β· 7 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– URI::FromHash β€” the manual, but make it slay πŸ’–

okay bestie, listen. this is URI::FromHash, a Perl module, and its whole personality is build a URI from a set of named parameters. that's literally the NAME line and honestly? it ate. no cap. ✨


🌸 VERSION 🌸

version 0.05 β€” that's the one, that's the version, don't @ me 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe, copy-paste ready:

use URI::FromHash qw( uri );

my $uri = uri(
    path  => '/some/path',
    query => { foo => 1, bar => 2 },
);

that's it. that's the whole flex. πŸ’…


✨ DESCRIPTION ✨

so this module gives you a simple one-subroutine "named parameters" style interface for creating URIs. one sub. named params. immaculate.

underneath the hood it uses URI.pm, bestie β€” though because of the simplified interface it may not support all possible options for all types of URIs. so like, it's the cute approachable version, not the everything-everywhere version. know the difference. πŸ™ˆ

it was created for the common case where you simply want a simple interface for creating syntactically correct URIs from known components (like a path and query string). doing this using the native URI.pm interface is, and I quote, rather tedious β€” it requires a number of method calls, which is particularly ugly when done inside a templating system such as Mason or TT2. like imagine doing all that inside a template. not me. couldn't be me. 😭


πŸ‘‘ FUNCTIONS πŸ‘‘

this module provides two functions and both of them are optionally exportable. pick your fave, or take both, we don't gatekeep.

πŸŽ€ uri( ... ) and uri_object( ... ) πŸŽ€

both of these functions accept the same set of parameters β€” except for one additional parameter that's allowed when you call uri(). one lil bonus. a treat. πŸ“

  • uri() simply returns a string representing a canonicalized URI based on the provided parameters.
  • uri_object() returns a new URI.pm object based on the given parameters.

and these are the parameters, bestie, all of them, in order, no skipping:

  • scheme β€” the URI's scheme. this one is optional, and if you don't give one you'll create a schemeless URI. which is genuinely useful when you want a URI to a path on the same server β€” exactly the kind of thing that commonly happens in <a> tags. iykyk. 🫢
  • host β€” yeah. the host. πŸ’œ
  • port β€” the port, queen. πŸŽ€
  • path β€” okay this one has layers. the path can be either a string or an array reference.
    • if an array reference is passed, each defined member of the array will be joined by a single forward slash (/).
    • if you're building a host-less URI and you want a leading slash, then make the first element of the array reference an empty string (q{}).
    • you can add a trailing slash by making the last element of the array reference an empty string.

see? layers. iconic behaviour honestly.

  • username β€” a string. optional. πŸ’…
  • password β€” a string. optional. πŸ”₯
  • fragment β€” all of these are optional strings which can be used to specify that part of the URI. yes, "all of these" includes username, password and fragment β€” they're a little trio, they come as a set. πŸ‘‘
  • query β€” this should be a hash reference of query parameters. the values for each key may be a scalar or an array reference β€” use an array reference when you want to provide multiple values for one key. so many values. so many keys. we love options. 🌈
  • query_separator β€” ⚠️ this option can only be provided when calling uri(). by default, it is a semi-colon (;). that's the default. don't forget it. ✨

πŸ’€ BUGS πŸ’€

please report any bugs or feature requests to bug-uri-fromhash@rt.cpan.org, or through the web interface at <http://rt.cpan.org>. the author says: "I will be notified, and then you'll automatically be notified of progress on your bug as I make changes." so like, you will get updates. that's a whole feedback loop. slay. πŸ¦‹


🌸 AUTHOR 🌸

Dave Rolsky <autarch@urth.org> β€” the author. the main character. give them their flowers. πŸ’


this software is Copyright (c) 2015 by Dave Rolsky.

this is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

periodt. legal said what it said. πŸ“œβœ¨


and that's the whole page, bestie 🫢 this was perl v5.34.0, dated 2022-06-28, and that's your URI::FromHash(3pm) β€” go build some URIs, you absolute legend. πŸ’…πŸŒˆπŸ’–