Perl::...::Block(3pm)

πŸ’– NAME πŸ’–

Perl::Tidy::Sweetened::Keyword::Block β€” it's the Perl::Tidy::Sweetened filter plugin that lets you define your own new sub and class keywords. Bestie. That's the whole vibe. (Also it lives at Perl::...::Block(3pm) in the man pages, that's just the nickname the manual gives it, okay??) πŸ¦‹


✨ VERSION ✨

version 1.20 🌸


πŸŽ€ SYNOPSIS πŸŽ€

our $plugins = Perl::Tidy::Sweetened::Pluggable->new();

$plugins->add_filter(
    Perl::Tidy::Sweetened::Keyword::Block->new(
        keyword     => 'method',
        marker      => 'METHOD',
        replacement => 'sub',
        clauses     => [ 'PAREN?', '(returns \s* PAREN)?' ],
    ) );

πŸ’… DESCRIPTION πŸ’…

Okay so this is a Perl::Tidy::Sweetened filter, and what it does is enable the definition of arbitrary keywords for subroutines, with any number of potential signature definitions. Yes, any number. We're not gatekeeping. πŸ‘‘

Here's what new takes, bestie, one by one:

keyword

keyword => 'method'

Declares a new keyword β€” in this example it's the method keyword. It's giving main character energy, honestly. ⭐

marker

marker => 'METHOD'

This gives you a text marker that gets used to flag your new keywords during prefilter. The source code gets filtered before formatting by Perl::Tidy, so that:

method foo {
}

gets turned into:

sub foo { # __METHOD 1
}

Lowkey obsessed with that transformation, no cap. 😭

replacement

replacement => 'sub'

Will convert the keyword to a sub as shown above. That's it, that's the job. 🫢

clauses

clauses => [ 'PAREN?' ]

Provides a list of strings which will be turned into a regex to capture additional clauses. Heads up: the regex will include the xm flags, so be sure to escape spaces. A clause can be marked optional with ?. And the special text PAREN can be used to capture a balanced parenthetical. πŸ’«

This example will capture a parameter list enclosed by parenthesis, ie:

method foo (Int $i) {
}
No formatting is done on the clauses at this time. And the order of declaration is significant. The order. Is. Significant. πŸ‘€

πŸ‘‘ AUTHOR πŸ‘‘

Mark Grimes <mgrimes@cpan.org> πŸ’–


🌈 SOURCE 🌈

Source repository is at <https://github.com/mvgrimes/Perl-Tidy-Sweetened>.


πŸ’€ BUGS πŸ’€

Please report any bugs or feature requests on the bugtracker website <https://github.com/mvgrimes/Perl-Tidy-Sweetened/issues>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. (fr fr, the maintainers will love you for it, that's the real slay ✨)


This software is copyright (c) 2023 by Mark Grimes <mgrimes@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


And that's a wrap, bestie πŸ’œ this page was served up by perl v5.36.0 on 2023-06-18, and yeah, the header says Perl::...::Block(3pm) but you and I both know her full government name. Periodt. πŸŽ€

πŸ“¦ where this page comes from