Esteemed monks, I'm hoping someone can help me.

I'm working on an app that uses Params::Validate in a number of places. Quite a few really. What I want to do is add a method in the base class that uses Contextual::Return. Herein lies the problem:

use Params::Validate qw(validate_pos validate SCALAR ARRAYREF HASHREF) +; use Contextual::Return;

BOOM! It took me a while to realize the problem here. Params::Validate is importing SCALAR, ARRAYREF and HASHREF tags into the current namespace.... and oh look, Contextual::Return uses those as well! ARG!

Now, I know what I can use the full package name with Params::Validate to get the various "type" validators and not import them like so:

use Params::Validate qw( validate_pos validate ); use Contextual::Return; # and later in the args to validate I could do: sub fun { my $self = shift; my $args = validate( @_, { fun => Params::Validate::ARRAYREF } ); return LIST { @{ $args{fun} } } ARRAYREF { $args{fun} } SCALAR { $#{$args{fun}} } DEFAULT { croak "illegal context" } }

but I'd have to go through all the modules and fix all the use statements and expand out the type checks to Params::Validate::ARRAYREF/SCALAR/HASHREF. I might even be able to automate something to do it for me... but that scares me. It's all over the place!

Now, the easy thing would be to do the same with Contextual::Return but I realized my Perl-fu is not as strong as TheDamian's (stunning realization, I know). It doesn't play well like that and from what I can see in the source (yes, you may laugh now at a very average Perl hacker trying to understand Damian's code) there's a whole lot going on that makes just specifying out the full package name a non-option (I've tried). So that means this doesn't work:

use Params::Validate qw( validate_pos validate SCALAR ARRAYREF HASHREF + ); use Contextual::Return qw(); # later, in a subroutine # this don't work! sub funner { return Contextual::Return::LIST { qw/Larry Curly Moe/ } Contextual::Return::ARRAYREF { [ qw/Larry Curly Moe/ ] } Contextual::Return::DEFAULT { croak "listy type contexts only +" } ; }

So, I HAVE a solution, but it seems a bit of a pain to have to go through ALL the code and change every use of Params::Validate in bunches of files so I can use Contextual::Return in one place. Can anyone help me be lazy? I really don't know how else I can stop these two modules from clashing.

Well... maybe I'll ask Rolsky and Damian to arm wrestle for the namespace. :D

Thanks for the assistance.

Updatery: fixed wrong module name in code

Updatery the Second: fixed missing bracket.

--
meraxes

In reply to lazily getting around an Exporter problem by meraxes

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!
  • 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, details, 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, summary, 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.