Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How do I write a new sub in a git cloned CPAN module and test it by bypassing the Original Module

by davido (Cardinal)
on Dec 20, 2016 at 16:17 UTC ( [id://1178221]=note: print w/replies, xml ) Need Help??


in reply to How do I write a new sub in a git cloned CPAN module and test it bypassing the Original Module

DateTime is an object oriented module. If you are forking it you may be doing it wrong.

Rather than fork DateTime, subclass it:

package MyDateTime; use parent qw(DateTime); sub is_leap_year { my $self = shift; my $ly = $self->SUPER::is_leap_year; return ($ly, ($ly ? 'intercalary' : 'standard')); } 1; package main; use MyDateTime; my $dt = MyDateTime->new(...); my @ly = $dt->is_leap_year; print "This is ", ($ly[0] ? 'leap ' : 'a normal '), "year, otherwise k +nown as $ly[1]\n";

The advantage to NOT modifying a locally adapted version of a CPAN module is that you won't have to keep abreast of future development for that module -- you won't be stuck either maintaining a fork of the module, or letting it grow stale.

By subclassing you get to leave the original module alone, so that it is free to continue evolving with bugfixes. As long as your subclass doesn't muck with the parent class's internals, and as long as the authors of DateTime don't break its calling interface, your subclass will continue to work even if the parent is updated with future bugfixes. Plus you don't have to worry about which version Perl is loading (the issue you're currently dealing with, but would certainly deal with again if you go the route of maintaining a patched version of DateTime).


Dave

  • Comment on Re: How do I write a new sub in a git cloned CPAN module and test it by bypassing the Original Module
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I write a new sub in a git cloned CPAN module and test it by bypassing the Original Module
by Anonymous Monk on Dec 21, 2016 at 02:04 UTC

    Thank you so much Dave. I am really touched that the author of the module himself replied my question. Awesome! Now understan why SawyerX had praised you in this video The Joy in What we Do

    I am looking to contribute to the module itself rather than sub classing it. I found the way in other monks reply. I will try out. Thanks again. :)

      I'm sorry that there's probably a misunderstanding on both sides. I didn't recognize that your plan was to contribute to the module, which is a different story entirely. If that's your intent, then I'm glad one of the other monks' solutions worked for you.

      I do want to set the record straight though: While it would be an honor to be mistaken for Dave Rolsky, I'm a different Dave (Oswald).


      Dave

        Sorry for the misunderstanding. I am glad that great perl module developers monks replied my question.

        Thank you all.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-23 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found