Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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;


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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

    What's my password?
    Create A New User
    [Corion]: ... in Pg, but that would mean that I'd have to deal with credentials and stuff :)
    [Corion]: In fact, the whole thing is just four simple programs, one App::scrape, another being DBIx::RunSQL, and one some glue to convert a JSON object into an SQL INSERT statement (+DBI connect/execute), so it would be an incredibly simple solution...
    [Corion]: ... but that simplicity falls down due to SQLite letting me down and me being too lazy to move to a real DB. Maybe DBD::CSV can handle window functions...
    [hippo]: Pg has the "trust" mechanism if you don't fancy using credentials for a trivial db.
    [Corion]: hippo: Oooh, that sounds quite nice - let me read the documentation on that :)
    [hippo]: https://www. docs/current/ static/auth- methods.html#AUTH- TRUST
    [erix]: or compile & run an instance as yourself (not user 'postgres')
    [erix]: easiest setup is to run with PG* env variables set, and a custom .pgpass files (can be a $PGPASSFILE)
    [Corion]: Hmm - "trust" sounds interesting, but I have still to find whether I can restrict that on a per-DB level ;)
    [Corion]: erix: Sure, but SQLite doesn't even need that :)

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (10)
    As of 2018-02-23 15:10 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (302 votes). Check out past polls.