[sf-perl] Can I silence experimental warnings in someone else's package?
George Hartzell
hartzell at alerce.com
Thu Nov 19 08:16:45 PST 2015
Hi Kevin,
Thanks. That "fixed" the problem.
I don't have a StackOverflow account, but if you think it's worthwhile, I'll set one up over the weekend and we can do an encore performance.
g.
Sent from a device that makes me type with two fingers.
> On Nov 18, 2015, at 9:46 AM, Kevin Frost <biztos at mac.com> wrote:
>
> Wow, that’s a tricky one. I thought I could get around it by subclassing Y::Foo and using the “experimentals” module but no luck.
>
> http://search.cpan.org/~dconway/experimentals-0.015/lib/experimentals.pm
>
> Instead I had to do the evil SIG trick, again with a subclass. That way your Project Y can do whatever they want, as long as they don’t much change Y::Foo on you; and you access it through X::Y::Foo, which looks like this:
>
> package X::Y::Foo;
>
> use strict;
> use warnings;
>
> BEGIN {
>
> local $SIG{'__WARN__'} = sub {};
> eval 'use base "Y::Foo";'
> }
>
> 1;
>
> At least for me, that works, as in:
>
> use strict;
> use warnings;
>
> use Test::More tests => 3;
> use Test::NoWarnings;
>
> use lib qw(.);
>
> BEGIN {
> use_ok('X::Bar');
> }
> is( X::Bar->baz, 'bat', 'drives one batty' );
>
> …which is, I assume, something like what you’re running, since you said the warnings are causing the build to die.
>
> By the way, for the warning-inducing Y::Foo I used this, the familiarity of which is not coincidental:
>
> package Y::Foo;
>
> use v5.14;
>
> my $THING = {};
>
> given ( $ENV{FOO} ) {
> $THING->{abc} = 1 when /^abc/;
> $THING->{def} = 1 when /^def/;
> $THING->{xyz} = 1 when /^xyz/;
> default { $THING->{nothing} = 1 }
> }
>
> sub bar { return 'bat'; }
>
> 1;
>
> …and in the interest of completeness, here’s my X::Bar, the stand-in for whatever actual use Project X makes of Y::Foo and thus the object of my tests:
>
> package X::Bar;
>
> use strict;
> use warnings;
>
> use X::Y::Foo;
>
> sub baz { return X::Y::Foo->bar; }
>
> 1;
>
> Hope that helps. You probably have to add a bunch of ‘no critic’ to X::Y::Foo, plus a note of POD explaining to future generations why you did such a thing.
>
> If you have a StackOverflow account please consider posting the question there, and I’ll post this answer too, so it might be more findable on the commercial Innernets.
>
> cheers
>
> — frosty
>
>
>> On Nov 18, 2015, at 5:32 PM, George Hartzell <hartzell at alerce.com> wrote:
>>
>> Hi All,
>>
>> I have a project X, that uses a package that's been installed by project Y, e.g. Y::Foo.pm. That package was written in the heady days, just after given/when were introduced and it makes profligate, but safe, use of them. I'm migrating project X forward to the modern era (Perl 5.18.2, sigh...) and Y::Foo's use of given/when generates warnings that, amongst other things, cause the compile tests to fail.
>>
>> I know how to fix the problem "at the source", but I can't get project Y to make an updated release.
>>
>> I can't figure out anything that I can do, in Project X's "using" package, that silences the warnings.
>>
>> At this point my options seem to be to install a private copy of the Y::Foo or to disable the tests (and live with the extra output).
>>
>> Can anyone suggest any other options?
>>
>> g.
>>
>> Sent from a device that makes me type with two fingers.
>> _______________________________________________
>> SanFrancisco-pm mailing list
>> SanFrancisco-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20151119/30c80cbe/attachment.html>
More information about the SanFrancisco-pm
mailing list