Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: From test harness to CPAN

by GrandFather (Saint)
on Apr 17, 2011 at 23:41 UTC ( [id://899851]=note: print w/replies, xml ) Need Help??


in reply to Re^2: From test harness to CPAN
in thread From test harness to CPAN

Most likely the 'load it if we need it' failed for a second object because PDL was already loaded. I was thinking more in terms of "use it if it's available" in any case. The following code implements that:

use strict; use warnings; package TestPDL; my $PDLLoaded = eval { require 'PDL.pm'; PDL->import (); 1; }; sub new { my ($class, %params) = @_; $params{havePDL} = $PDLLoaded; return bless \%params, $class; } package main; my $obj = TestPDL->new (); my $obj2 = TestPDL->new (); print $obj2->{havePDL} ? "Have PDL available" : "PDL not present or object create failed";

I'd write one basic object that does common stuff then derive from that to specialise for additional capabilities. Following that thought, I'd arrange the name space as Sport::Analytics::SRS for the basic module then Sport::Analytics::SRS::Cricket for the Cricket specialisation.

This technique allows a PDL only implementation for tricky or computationally expensive stuff with a pure Perl implementation provided either in the module or in a derived class at some point in the future if there is a need for it.

True laziness is hard work

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-26 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found