Skip Menu |

This queue is for tickets about the Class-MethodMaker CPAN distribution.

Report information
The Basics
Id: 1230
Status: resolved
Priority: 0/
Queue: Class-MethodMaker

People
Owner: Nobody in particular
Requestors: kevin [...] justanyone.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.06
Fixed in: (no value)



Subject: Documentation / Feature Issue in Class::MethodMaker
Hello! I like your module. I found out about it in the Damian Conway OO Perl book. I'd like to suggest something, though, about the way it operates. There's no way to default a list of values in easily; at least I couldn't figure it out. The documentation doesn't include an example of how to do this. I'm wondering if there actually is an easy way to do this. I want to be able to specify the default values for the class in the class itself, and override those values in with the call to new with a hash. Pretty straightforward, methinks. Below is code that I found works to do this task. Perhaps you could include this code in your readme file under 'EXAMPLES'. Or, you could figure out how to make this easier for us all and add that as a feature. If the feature to do this easily already exists, please document exactly how to do it???? Please??? Thanks, Cordially yours, -- Kevin Rice CPAN ID: KEVINRICE kevin@justanyone.com Code Follows: 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.
Date: Mon, 30 Sep 2002 17:04:34 +0000
From: "Martyn J. Pearce" <fluffy [...] inpharmatica.co.uk>
To: "Kevin J.Rice via RT" <bug-Class-MethodMaker [...] rt.cpan.org>
Subject: Re: [cpan #1230] Documentation / Feature Issue in Class::MethodMaker
Hi Kevin, On Tue, Jul 02, 2002 at 12:50:26PM -0400, Kevin J.Rice via RT wrote: Show quoted text
> I like your module. I found out about it in the Damian Conway OO Perl book. > I'd like to suggest something, though, about the way it operates. There's > no way to default a list of values in easily; at least I couldn't figure it > out. The documentation doesn't include an example of how to do this. I'm > wondering if there actually is an easy way to do this. > > I want to be able to specify the default values for the class in the class > itself, and override those values in with the call to new with a hash. > Pretty straightforward, methinks. > > Below is code that I found works to do this task. Perhaps you could include > this code in your readme file under 'EXAMPLES'. Or, you could figure out > how to make this easier for us all and add that as a feature. If the > feature to do this easily already exists, please document exactly how to do > it???? Please???
I have included in 1.07, under new_hash_init, your code as an example (slightly edited). Thanks for that. C::MM 2 will support default values across all its types. It's taking a lot longer than I hoped --- and I'm sorry that this took so long to reply to. Cheers, Mx.