Perl::...appings(3pm)
πΈ NAME πΈ
Perl::Critic::Policy::BuiltinFunctions::ProhibitComplexMappings β map blocks should have a single statement. This page is the Perl::...appings(3pm) entry in User Contributed Perl Documentation, and bestie, it is here to keep your map blocks from trying to do too much π
.
π«Ά AFFILIATION π«Ά
This Policy is part of the core Perl::Critic distribution. Slay.
β¨ DESCRIPTION β¨
Okay so real talk: the map function can be confusing to novices in the best of circumstances. Mappings with multiple statements are even worse. Theyβre also a maintainerβs nightmare because any added complexity decreases readability precipitously π. Why? Because map is traditionally a one-liner converting one array to another. Trying to cram lots of functionality into a one-liner is a bad idea in general, fr fr.
The best solutions to a complex mapping are:
- write a subroutine that performs the manipulation and call that from
map; - rewrite the
mapas aforloop.
π CAVEATS π
This policy currently misses some compound statements inside of the map. For example, the following code incorrectly does not trigger a violation:
map { do { foo(); bar() } } @list
Not me pointing out the gap so you know exactly whatβs up π.
π CONFIGURATION π
By default this policy flags any mappings with more than one statement. While we do not recommend it, you can increase this limit as follows in a .perlcriticrc file:
[BuiltinFunctions::ProhibitComplexMappings]
max_statements = 2
πΈ AUTHOR πΈ
Chris Dolan <cdolan@cpan.org>
π CREDITS π
Initial development of this policy was supported by a grant from the Perl Foundation. Iconic behavior honestly π«Ά.
π COPYRIGHT π
Copyright (c) 2007-2011 Chris Dolan.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Bye bestie π β this page came from perl v5.42.0, dated 2024-10-23. Periodt β¨.
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms