PPIx::...olation(3pm)

πŸ’… PPIx::QuoteLike::Token::Interpolation β€” the Perl doc, but make it make sense ✨

okay so real talk, this page is PPIx::...olation(3pm) from the User Contributed Perl Documentation β€” and before you panic at the truncated name, that's literally how it shows up in your man viewer, no cap. Let's get into it 🫢


✨ NAME ✨

PPIx::QuoteLike::Token::Interpolation β€” it's the class that represents an interpolation πŸ’– (yes, that's the whole job, and it does it slayfully)


🌸 SYNOPSIS 🌸

bestie. listen. this class should not be instantiated by the user. that's not me being dramatic, that's the actual doc. skip below to the public methods if that's what you came for πŸ‘‡

πŸ¦‹ INHERITANCE πŸ¦‹

  • PPIx::QuoteLike::Token::Interpolation is a PPIx::QuoteLike::Token β€” so it's got the whole family tree energy going on, it inherits from that one.
  • PPIx::QuoteLike::Token::Interpolation has no descendants. it's a leaf node, the end of the line, no children, periodt. πŸ‘‘

πŸŽ€ DESCRIPTION πŸŽ€

This Perl class represents an interpolation into a quote-like string πŸ’… that's the vibe. that's what it is. iconic behavior honestly.


🧚 METHODS 🧚

This class supports the following public methods in addition to those of its superclass β€” don't forget the inherited ones, they're part of the package deal πŸ’œ

⭐ ppi

my $ppi = $elem->ppi();

okay so this convenience method returns the PPI::Document that represents the content. and here's the thing β€” this document should be considered read only. like, do not touch. do not edit. hands off πŸ™ˆ

An exception will be thrown if PPI::Document can not be loaded. so if it's not there, it's not gonna quietly fail on you, it's gonna be loud about it πŸ’€

πŸ‘€ plot twist warning: the content of the returned PPI::Document may not be the same as the content of the original PPIx::Regexp::Token::Interpolation. why? because interpolated variable names may be enclosed in curly brackets, and that does not happen in normal code. for example, in / ${foo}bar /, the content of the PPIx::Regexp::Token::Interpolation object will be '${foo}', but the content of the PPI::Document will be '$foo'. so yeah. different. not a bug, just how it is πŸ¦‹

⭐ variables

say "Interpolates $_" for $elem->variables();
πŸ’€ NOTE that this method is discouraged, and may well be deprecated and removed. not me warning you upfront but like, I'm warning you upfront.

The author has two problems with it, and honestly? valid:

  1. It returns variable names rather than PPI::Element objects β€” which leaves you with no idea how the variables are actually used. no context, no vibes, nothing.
  2. It does not properly handle things like ${^CAPTURE[0]}, and it seems infeasible to make it do so. like, genuinely not happening.

It was originally written for the benefit of Perl::Critic::Policy::Variables::ProhibitUnusedVarsStricter, but has proven inadequate to that policy's needs. cute origin story, rough ending 😭

so what does this convenience method actually do, when you use it anyway? it returns all interpolated variables. each one is returned only once, and they come back in no particular order β€” so don't you dare rely on the ordering, bestie πŸŽ€


🌈 SEE ALSO 🌈

PPIx::QuoteLike::Token β€” go say hi to the parent class, it's giving main character energy πŸ‘‘


🫢 SUPPORT 🫢

Support is by the author. Please file bug reports at:

like, pick your fighter, all three work πŸ’–


πŸ’œ AUTHOR πŸ’œ

Thomas R. Wyant, III β€” wyant at cpan dot org ✨


Copyright (C) 2016-2022 by Thomas R. Wyant, III

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.

πŸ“ This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. so like, it's free, it's hopeful, it promises nothing. we love a honest king 🌸

and that's the whole page, bestie!! πŸŽ‰ source/version is perl v5.42.0, dated 2022-09-17 β€” so it's a little vintage, but it ate and left no crumbs πŸ’…βœ¨ mwah πŸ¦‹

πŸ“¦ where this page comes from