Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Thanks to a nudge from the post above (thanks!) I tried delegating to Subroutines::RequireArgUnpacking instead of sub-classing and now I can exclude that one but have my policy still execute.

Here is the gist of the technique I used. Please keep in mind that this is strictly proof of concept at this point. I will post the final code to Meditations when it is done as an RFC. I know already that I will want further suggestions on how to fine tune the regex expressions being used as well as how to go about integrating the existing P::C test harness for regression tests.

package Perl::Critic::Policy::Local::RequireArgUnpackOrShift; use strict; use warnings; use Readonly; use Perl::Critic::Utils qw< :booleans :characters :severities words_from_string >; use Perl::Critic::Policy::Subroutines::RequireArgUnpacking; use base 'Perl::Critic::Policy'; Readonly::Scalar my $AT_ARG => q{@_}; ## no critic (InterpolationOfMet +achars) Readonly::Scalar my $DESC => qq{Always unpack $AT_ARG first}; Readonly::Scalar my $EXPL => [178]; my $rau = Perl::Critic::Policy::Subroutines::RequireArgUnpacking->new; my @delegations = ( qw( supported_parameters default_severity default_themes applies_to _is_size_check _is_postfix_foreach _is_cast_of_array _is_cast_of_scalar _get_arg_symbols _magic_finder ) ); my @has_self = ( qw( _is_unpack _is_delegation ) ); { no strict 'refs'; for (@delegations) { my $attribute = $_; *{ __PACKAGE__ . '::' . $attribute } = sub { my $fq_sname = join('::',ref($rau),$attribute); return &{$fq_sname}(@_); }; } for (@has_self) { my $attribute = $_; *{ __PACKAGE__ . '::' . $attribute } = sub { my $self = shift; return $rau->$attribute(@_); }; } } sub violates { my ( $self, $elem, undef ) = @_; warn "In OrShift violates\n"; # do some nifty new stuff here, delegate all methods and subroutin +es # to the original policy except for my tests. return; } 1;

Update

Corrected items in the arrays at the top.

Before someone asks, yes, I could have done the delegation much easier with Moose. I decided against that because Perl::Critic does not use Moose and is 5.6 compliant. I wanted to keep anything I added the same if it is eventually released to CPAN.

Second, I did not use AUTOLOAD for two reasons: a) anything that depends upon using a "obj->can()" test would fail, and b) I had to have two different types of delegation based on whether or not the call would be to a simple sub-routine or an object method call (passing in the object as the first element.)

On time, cheap, compliant with final specs. Pick two.

In reply to Re: Problems with overriding a Perl::Critic policy - SOLVED by boftx
in thread Problems with overriding a Perl::Critic policy - SOLVED by boftx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (19)
    As of 2015-07-02 19:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (45 votes), past polls