Perl::...rgBless(3pm)

✨ NAME ✨

Okay so the manual name is Perl::...rgBless(3pm), and the policy bestie in question is Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless β€” and its whole thing is: Write "bless {}, $class;" instead of just "bless {};". Periodt. πŸ’…


🌸 AFFILIATION 🌸

This Policy is part of the core Perl::Critic distribution. It's giving core-distribution royalty, no cap πŸ‘‘.


πŸ¦‹ DESCRIPTION πŸ¦‹

Always use the two-argument form of bless because it allows subclasses to inherit your constructor. That's the tea, and it's iconic β˜•βœ¨

sub new {
    my $class = shift;
    my $self = bless {};          # not ok
    my $self = bless {}, $class;  # ok
    return $self;
}

πŸŽ€ CONFIGURATION πŸŽ€

This Policy is not configurable except for the standard options. That's it, that's the config vibe 🫢


πŸ’œ AUTHOR πŸ’œ

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>


Copyright (c) 2005-2023 Imaginative Software Systems

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


Source/version vibe check: perl v5.42.0, dated 2024-10-23, manual Perl::...rgBless(3pm) β€” bye bestie, go bless with two args and slay πŸ’…βœ¨

πŸ“¦ where this page comes from