Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: Class::MethodMaker initialization of default values

( #178904=categorized answer: print w/ replies, xml ) Need Help??

Q&A > object-oriented programming > Class::MethodMaker initialization of default values contributed by justanyone

Okay, So this helped but it didn't solve it. I finally played with this enough - the real answer is (tested as correct):
package Simple; use Class::MethodMaker get_set => [qw(a b)], new_with_init => 'new'; sub init { my $self = shift; my %in_args = @_; my %default_args = ( b => "default"); my %final_args = (%default_args, %in_args); foreach my $thiskey (keys(%final_args)) { $self->{$thiskey} = $final_args{$thiskey}; } return; } -------------- in use_it.pl --------- use Simple; my $test = new Simple (a=>1); # now a==1, b==default. my $test = new Simple (a=>1, b=>2); # now a==1, b==2.
I've reported the contents of this posting to the Class::MethodMaker author to request that this information be included in the readme, or a modification to the module be made so it's easier to do.

Thanks for the assistance, samtregar, you started me on the right path. I appreciate it.

Cordially, -- Kevin

Comment on Answer: Class::MethodMaker initialization of default values
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-08-21 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls