jessmlilly has asked for the wisdom of the Perl Monks concerning the following question:

I just started using Perl::Critic (perlciritc from the command line). I want to use a lot of the best practices from Chapter 15 of Damian Conway's book (Objects and Inside-Out Object Oriented design). The system I am working on uses this very heavily. I can only find three existing policies.

For example, I can't find this rule from page 336: "Always provide a destructor for every inside-out class". Are these policies missing from the Perl::Critic::Policy's because of Moose? (Which I have never used)

Also, I cannot seem to find any of the policies I want on Google or CPAN. The policies are not in Perl::Critic::More, Perl::Critic::Bangs, etc. I'm searching for the policies that would be on pages: 322, 323, 333, 334, 336, 340, etc. The only ones I have been able to find are these:

# Perl Best Practices page 349 [Perl::Critic::Policy::Objects::ProhibitIndirectSyntax] # Perl Best Practices page 360 [Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA] # Perl Best Practices page 365 [Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless]

I hope I will not have to create these policies by myself. Do they already exist somewhere? Thanks!

Replies are listed 'Best First'.
Re: Why can't I find all of the Damian Conway Perl::Critic Policies?
by toolic (Bishop) on Jul 09, 2012 at 20:06 UTC
Re: Why can't I find all of the Damian Conway Perl::Critic Policies?
by tobyink (Canon) on Jul 09, 2012 at 20:29 UTC

    As the previous answer said, although many Perl::Critic policies are based on the PBP book, not all ideas from PBP have had Perl::Critic policies written for them. Some of them lend themselves to easy automated checking, such as "#209 never use the one argument form of bless"; while others like "#237 never assume that a warning-free compilation implies correctness" seem silly to even attempt to automatically test.

    By the way, if you use fieldhashes (see Hash::FieldHash or Hash::Util::FieldHash) then there's no need to provide destructors for inside out objects.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      There's an easy solution to that specific one:

      BEGIN { warn "Warning: Rule 237 applies - Appearances can be deceiving.\n"; }

      Then you just have to worry about people who ignore warnings.

Re: Why can't I find all of the Damian Conway Perl::Critic Policies?
by Anonymous Monk on Jul 09, 2012 at 20:50 UTC
    PBP is outdated and should only be used as a guide, not a bible. For instance, Conway was a big proponent of inside-out objects, but they are no longer in fashion.

      Quote from Chapter 1 of PBP: "But remember that each of[sic] piece of advice is a guidline."

      Changes in perl have made some of the advice obsolete. I believe that changes in fasion should be taken as warning when deciding wheteher or not accept the related advice.

Re: Why can't I find all of the Damian Conway Perl::Critic Policies?
by jessmlilly (Novice) on Jul 10, 2012 at 16:21 UTC

    Wow! I can't believe how fast you all responded. Thank you for your constructive comments.

    I would get pretty big resistance from the team if I suggested changing from Inside-Out Object to Moose, but I will start putting a bug in their ears. :)

    I guess we should say that best practices evolve as Perl evolves.