Perl::...odCalls(3pm)

πŸ’… NAME πŸ’…

okay so this page is the Perl::...odCalls(3pm) manual β€” User Contributed Perl Documentation energy, fr fr β€” and the policy it's serving is Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls. Long chains of method calls indicate tightly coupled code. periodt. πŸ’–

🫢 AFFILIATION 🫢

This Policy is part of the core Perl::Critic distribution. no cap, it's core. ✨

πŸ”₯ DESCRIPTION πŸ”₯

A long chain of method calls usually indicates that the code knows too much about the interrelationships between objects. If the code is able to directly navigate far down a network of objects, then when the network changes structure in the future, the code will need to be modified to deal with the change. The code is too tightly coupled and is brittle. 😭

here's the vibe check, with the exact allowed-ness:

$x = $y->a;           #ok
$x = $y->a->b;        #ok
$x = $y->a->b->c;     #questionable, but allowed by default
$x = $y->a->b->c->d;  #not ok

πŸŽ€ CONFIGURATION πŸŽ€

this policy has one option, bestie:

  • max_chain_length β€” controls how far the code is allowed to navigate. The default value is 3. 🎯

🌈 TO DO 🌈

Add a class_method_exemptions option to allow for things like:

File::Find::Rule
    ->name('*.blah')
    ->not_name('thingy')
    ->readable()
    ->directory()
    ->in(@roots);

πŸ‘‘ AUTHOR πŸ‘‘

Elliot Shank <perl@galumph.com> β€” icon behavior. πŸ’…

Copyright (c) 2007-2011 Elliot Shank.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. 🫢


mwah πŸ’‹ β€” perl v5.42.0, dated 2024-10-23, and that's the Perl::...odCalls(3pm) page signing off, bestie. πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from