I've had to do exactly that with Class::MethodMaker. I needed to initialize an object with a LOT of data (and a LOT of method calls) and initializing the object through repeated method calls was S-L-O-W. So, I subverted the regular constructor with my own:
package Datawarehouse::Employee;
use Class::MethodMaker
new_with_init => 'new';
sub init {
# ...Load up a whole lot of data
# Bless my own object into the class
Datawarehouse::Employee->new_new(\%args);
}
sub new_new {
# This constructor is a HELL of alot faster than creating an
# object by calling accessor methods one by one.
my $class = shift;
my $args = shift;
my $obj = bless $args, $class; # Loading the whole hash as one
}
If you do this while using the key_attrib parameter in Class::MethodMaker you'll need to call the key_attrib method explicitly so that your hand-made object is tracked like the regular one's are. Looking at the Class::MethodMaker source code is a great way of figuring out exactly what's going on with the autogenerated methods.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|