in reply to Re^5: Upgrade-proofing overridden subroutines
in thread Upgrade-proofing overridden subroutines

I was meaning "what the code is currently doing" in the context of Adrian's suggestion that it could be safe to run a sub to know if it behaves correctly. That way I could always run the code after an upgrade to see if its behavior has changed. The problem with that is even if I know what the code is currently doing and therefore deem it safe to run, I don't know what it will be doing in the future, and thus I don't know if it will be safe to run. Thus, Adrian's solution can't work.

As for the problems with forking, you can google for that pretty easily. The pros and cons are numerous and well spelled out. To fork, you really need a compelling reason to but too many forks spoil the broth. Even a great fork can meet serious resistance. Look at Module::Build. Many people who didn't understand the problems with ExtUtils::MakeMaker were pretty vehement that Module::Build was a bad thing. Go figure. (well, there was that little matter of PREFIX. It's horribly broken but people want its broken behavior).

If you fork privately, you have to maintain it in-house. For small projects this is not so bad. For large projects, it gets hairy. If you want to fork it publicly, you might get community support. You might get ingnored. You might get community derision. Imagine if Module::Build was one of the offenders (it has bugs reported, but it's certainly not one of the offenders in question since it's being so actively developed). Could you reasonably fork that and expect it to work on the hundreds of different platforms it's supposed to work on? Could you expect the community to help with a fork they may not see the merit of?

That's not to say that forking is always bad. I'm just pointing out that forking is a very serious issue and if the code isn't trivial, it shouldn't be done on a whim.

Cheers,
Ovid

New address of my CGI Course.

  • Comment on Re^6: Upgrade-proofing overridden subroutines

Replies are listed 'Best First'.
Re^7: Upgrade-proofing overridden subroutines
by rir (Vicar) on Aug 16, 2006 at 22:32 UTC
    Update: Added output of sample code.

    I apologize--I feel like I took your question too concretely, that I missed a modest mentoring tone in your first post, and that I provoked you to the defense of your module. You tossed out Module::Build as if it were germane when we were talking about neglected modules. That seemed red-herringish to me; did I miss a point?

    If you fork privately, you have to maintain it in-house.

    The wisdom I was trying to share:

    • You are already maintaining this code and you should not deny it just because it is an unpleasant reality.
    • There is no real protection against future changes in not-invented-here code.

    Adrianh's solution, if usable, has the advantage of clarity.

    For readability and lack of any downside of which I can think, my first choice for an outside patch would be to redefine the problem.

    use Foo; package Foo; { no warnings "redefine"; sub foo { 'different foo' } } package resume_former_namespace; ...

    I like the idea of aliasing away the problem but I can see how that could be very confusing to those year-later-and-you're-gone maintainers. It is not really possible to predict what semantics those folk will expect. Should foo or Foo::foo be overridden in below? I'd avoid that issue unless I need the flexibility.

    Be well,
    rir

    #!/usr/bin/perl use warnings; use strict; use Foo; use Sub::Override; sub fixed_foo { "I'm overridden foo" } my $override = Sub::Override->new; $override->replace( 'Foo::foo' => \&fixed_foo ); # maybe 'foo' print "Foo::Ridden: ", Foo::foo(), $/; print "Foo::Ridden: ", Foo::bar, $/; print " ::Ridden: ", foo(), $/; $override->restore; print " ::Orig: ", foo(), $/;
    File Foo.pm
    package Foo; use Exporter; our @ISA = 'Exporter'; our @EXPORT = qw/ foo bar /; sub foo { "I'm foo" } sub bar { foo() . 'bar' } 1;
    Output of above code overriding Foo::foo.
    Foo::Ridden: I'm overridden foo Foo::Ridden: I'm overridden foobar ::Ridden: I'm foo ::Orig: I'm foo
    Results of same code overriding foo.
    Foo::Ridden: I'm foo Foo::Ridden: I'm foobar ::Ridden: I'm overridden foo ::Orig: I'm foo
    ~

      Whoa! That's something I hadn't thought about. Thanks for bringing it to my attention. Yes, it will likely confuse people and that's probably something I should add to the docs.

      Cheers,
      Ovid

      New address of my CGI Course.

        If you find a good way to explain this behaviour to folks who don't really understand aliasing and just want to "get it to work", let me know.

        I think your solution is too cute for the task. By putting such code in your codebase you endorse it for such problems; I feel this responsibility myself and I have no visibility nor reputation as a Perl expert. Since it is an approved solution, it will get used to fix the five other problem subs in Foo that featuritis may uncover. That is the tangle of interactions I would not induce.

        The way I see to make the semantics predictable is to override both Foo::foo and foo, but I haven't thought out the timing and interactions of multiple usages.

        My redefinition solution has the same weakness and should be used thusly:

        # File: My_Foo.pm use Foo; package Foo; no warnings 'redefine'; sub Foo { "redefined Foo" } 1;
        Then make any other use of Foo illegal. I'm a fan of linting code for such things during the build process.

        Be well,
        rir