Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Converting common subroutines as a module

by Zaxo (Archbishop)
on Nov 01, 2006 at 19:04 UTC ( [id://581734]=note: print w/replies, xml ) Need Help??


in reply to Converting common subroutines as a module

Since your subs all seem to take a CGI instance as an argument, you could subclass CGI.pm as Site::CGI and use that instead of CGI.pm in the top level scripts. That would help prevent putting functions with dissimilar purposes in your Common.pm.

The subclassing mechanism is not too difficult. The basic steps are:

package Site::CGI; use CGI; @ISA = qw/CGI/; # subroutine definitions, object instance is first arg # . . . 1;
Save that file as Site/CGI.pm somewhere in your @INC path.

You would then, in top level scripts, say,

use Site::CGI; # instead of use CGI; my $query = Site::CGI->new; # . . . print $query->my_sub; # etc

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-26 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found