Router...bMapper(3pm)

πŸ’… Router::Simple::SubMapper β€” like, the submapper era

ok so bestie, this is a page from the User Contributed Perl Documentation, and the manual name you're looking at is literally Router...bMapper(3pm) β€” say it with me, iconic. It's Router::Simple::SubMapper, and she's here to make your routes cute and DRY. Let's go πŸŽ€


✨ NAME ✨

Router::Simple::SubMapper β€” the submapper. that's it, that's the whole name, she's mysterious like that πŸ¦‹


🌸 SYNOPSIS 🌸

ok look at this little beauty:

use Router::Simple;

my $router = Router::Simple->new();
my $s = $router->submapper('/entry/{id}', {controller => 'Entry'});
$s->connect('/edit' => {action => 'edit'})
  ->connect('/show' => {action => 'show'});

see how she set up /entry/{id} once and then just kept stacking routes on top? that's the whole vibe. main character energy fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so Router::Simple::SubMapper is the sub-mapper for Router::Simple β€” it's giving "personal assistant for your router". this class provides shorthand to create routes that have common parts, so you're not out here copy-pasting the same prefix forty times like a clown 😭

basically: shared bits go in one place, and you chain the rest. no cap, it slaps ✨


πŸ”₯ METHODS πŸ”₯

  • my $submapper = $router->submapper(%args); β€” hmm okay, real talk: do not call this method directly. like, i'm serious, don't. you should create a new instance from $router->submapper(%args) instead. that's the correct way, periodt πŸ‘‘
  • $submapper->connect(@args) β€” this method creates a new route to the parent $router with @args plus the arguments of ->submapper(). so all your shared stuff gets folded in automatically, obsessed.

and the best part? this method returns $submapper itself for method-chain. yes queen, chaining πŸ’–

  • $submapper->submapper(%args) β€” so submapper() can be called recursively to build nested routes. routes inside routes inside routes, it's giving inception but make it cute 🧚

this method also returns $submapper itself for method-chain. chain away bestie πŸ”—


πŸ‘‘ SEE ALSO πŸ‘‘

  • Router::Simple β€” the parent router, the mothership, the OG. go read her page too 🫢

lowkey reminder: the ->submapper() constructor isn't for you to call directly, and both connect() and submapper() hand you back the $submapper object so you can keep chaining. that's the whole trick, don't overthink it πŸ’œ

and that's the page, bestie! 🌈 this doc came to you courtesy of perl v5.42.0, dated 2015-04-13 β€” yes she's an elder but she still ate πŸ’€βœ¨ mwah πŸ’‹

πŸ“¦ where this page comes from