Perl::C...wMethod(3)

πŸ“¦
version 1.05 Β· 2 versions
, in fedora 43

πŸ’– Perl::C...wMethod(3) πŸ’–

okay bestie, welcome to the manual page for Perl::Critic::Policy::Moose::ProhibitNewMethod β€” yes that's a whole mouthful, the header up top just calls it Perl::C...wMethod(3) because even man pages gotta truncate, and it lives in the User Contributed Perl Documentation section. she's niche, she's opinionated, she's here to stop you from doing a thing. let's get into it πŸŽ€


✨ NAME ✨

Perl::Critic::Policy::Moose::ProhibitNewMethod β€” don't override Moose's standard constructors. that's it, that's the whole personality. πŸ’…


🌸 VERSION 🌸

version 1.05 β€” she's been around a minute, she knows what she's talking about.


πŸ¦‹ DESCRIPTION πŸ¦‹

so like. overriding new() on a Moose class? it's giving chaos. it causes a whole bunch of problems, including:

  • speed issues (she's slow now, not slay)
  • problems with the order of invocation of constructors when multiple inheritance is involved

the way that multiple inheritance just does NOT play nice with a hand-rolled new()... yeah. 😭

instead, bestie, use BUILDARGS() and BUILD(). those are the correct lil hooks, they exist for exactly this, use them. periodt. ✨


πŸŽ€ AFFILIATION πŸŽ€

this policy is part of Perl::Critic::Moose. she's not out here alone, she's got a whole squad.


πŸ’œ CONFIGURATION πŸ’œ

there is a single option, and it's called equivalent_modules. what does it do? it lets you specify modules that should be treated the exact same as Moose and Moose::Role β€” like, if you were doing something with Moose::Exporter, iykyk. πŸ‘‘

for example, if you were to have this in your .perlcriticrc file:

[Moose::ProhibitNewMethod]
equivalent_modules = MyCompany::Moose MooseX::NewThing

then the following code would result in a violation:

package Baz;

use MyCompany::Moose;

sub new {
    ...
}

not me catching you in 4K. πŸ™ˆ the policy sees MyCompany::Moose and goes "that's a Moose, actually" and flags your sub new. iconic behavior fr fr.


🌈 SEE ALSO 🌈

  • Moose::Manual::Construction
  • Moose::Manual::BestPractices

go read these, they're the required reading bestie, they'll explain the whole construction vibe properly. 🫢


πŸ’€ SUPPORT πŸ’€

bugs may be submitted through the RT bug tracker <http://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Critic-Moose> (or <bug-perl-critic-moose@rt.cpan.org>).

she is also usually active on IRC as 'drolsky' on "irc://irc.perl.org" β€” so if you gotta talk to a human, that's the human. 🌸


⭐ AUTHORS ⭐

  • Elliot Shank <perl@galumph.com>
  • Dave Rolsky <autarch@urth.org>

absolute legends, both of them. πŸ‘‘


this software is copyright (c) 2008 - 2016 by Elliot Shank.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go off, but with the terms, okay? πŸ’–


and that's the whole page bestie!! this manual page was served to you by perl v5.42.0, dated 2025-07-25, and honestly? iconic of it. mwah πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from