Skip Menu |

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

Report information
The Basics
Id: 15408
Status: resolved
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: me [...] heyjay.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Simpler way to specify :ATTR
Hi, Maybe I don't fully understand how to use Class::Std, but it seems verbose trying to build a class with many attributes. Since the init_arg, set, and get are all going to be using the same <tag>, why have to duplicate the effort? Seems like a recipe for a typo. Instead of: { %name_of :ATTR(:init_arg<name> :get<name> :set<name>); } Do: { %name_of :ATTR(:as<name> :init_arg :get :set); } For example, below I have a simple class I'm creating, all the attributes are read and write, one has a default. Building with Class::Std the definition gets hairy (especially trying to keep the linesize < 80) I would have supplied a patch, but didn't know where to begin once I started looking at the source to Class::Std thanks Jay use Class::Std;use Class::Std; { %combo_legs_of :ATTR(init_arg=>combo_legs :set<combo_legs> :get<combo_legs>); %currency_of :ATTR(init_arg=>currency :set<currency> :get<currency>); %exchange_of :ATTR(init_arg=>exchange :set<exchange> :get<exchange>); %expiry_of :ATTR(init_arg=>expiry :set<expiry> :get<expiry>); %local_symbol_of :ATTR(init_arg=>local_symbol :set<local_symbol> :get<local_symbol>); %multiplier_of :ATTR(init_arg=>multiplier :set<multiplier> :get<multiplier>); %primary_exchange_of :ATTR(init_arg=>primary_exchange :set<primary_exchange> :get<primary_exchange>); %right_of :ATTR(init_arg=>right :set<right> :get<right>); %security_type_of :ATTR(init_arg=>security_type :set<security_type> :get<security_type>); %strike_of :ATTR(init_arg=>strike :default(0) :set<strike> :get<strike>); %symbol_of :ATTR(init_arg=>symbol :set<symbol> :get<symbol>); }
Date: Sun, 30 Oct 2005 22:10:33 -0500
To: bug-Class-Std [...] rt.cpan.org
Subject: Re: [cpan #15408] Simpler way to specify :ATTR
From: Damian Conway <thoughtstream [...] gmail.com>
RT-Send-Cc:
Actually, the next version will have a :name<attrname> option that sets all of :get :set and :init_arg Damian
From: me [...] heyjay.com
[damian@conway.org - Sun Oct 30 22:10:52 2005]: Show quoted text
> Actually, the next version will have a :name<attrname> option that sets > all of :get :set and :init_arg > > Damian
Way ahead of me huh? That's good news. But it seems one loses fine grain control with the new syntax, in that you can't create a readonly attr using the :name<> syntax. Any hints at the timeframe for the new version? Thanks Jay
Date: Tue, 01 Nov 2005 12:05:33 -0500
To: bug-Class-Std [...] rt.cpan.org
Subject: Re: [cpan #15408] Simpler way to specify :ATTR
From: Damian Conway <thoughtstream [...] gmail.com>
RT-Send-Cc:
Show quoted text
> Way ahead of me huh? That's good news.
Well, not "way", but a little. :-) Show quoted text
> But it seems one loses fine grain control with the new syntax, in that > you can't create a readonly attr using the :name<> syntax.
That's right. My problem is that your proposed syntax: :ATTR( :name<foo> :get ) really means (in Perl 6 notation): :ATTR( :name<foo> :get(1) ) which produces a C<get_1> accessor for the attribute. :-( In weighing it up, I didn't feel that: :ATTR( :get<foo> :init_arg<foo> ) is too onerous for read-only accessors. Although, I must say, I *am* tempted to change the behaviour of C<:name> so that it only creates a get_ accessor and specifies an initializer arg. That way it would be easier to specify read-only attributes: :ATTR( :name<foo> ) and the more dangerous read/write accessors would be the ones that require the extra effort: :ATTR( :name<foo> :set<foo> ) Do you think that would be a better default? Damian
From: Peter Scott
[damian@conway.org - Tue Nov 1 16:48:30 2005]: Show quoted text
> That's right. My problem is that your proposed syntax: > > :ATTR( :name<foo> :get ) > > really means (in Perl 6 notation): > > :ATTR( :name<foo> :get(1) ) > > which produces a C<get_1> accessor for the attribute. :-(
Will :ATTR( :name<foo> :get<> ) work?
From: dmuey [...] cpan.org
On Tue Dec 06 10:16:07 2005, PJS wrote: Show quoted text
> [damian@conway.org - Tue Nov 1 16:48:30 2005]:
> > That's right. My problem is that your proposed syntax: > > > > :ATTR( :name<foo> :get ) > > > > really means (in Perl 6 notation): > > > > :ATTR( :name<foo> :get(1) ) > > > > which produces a C<get_1> accessor for the attribute. :-(
> > Will > > :ATTR( :name<foo> :get<> ) > > work?
In a sense yes, : multivac:~ dmuey$ perl -le 'package X;use Class::Std; { my %x : ATTR(:name<foo> get<>) }package main;my $x=X->new({foo=>2});print $x->get_foo(); print $x->set_foo(3);print $x->get_foo();' 2 2 3 multivac:~ dmuey$ but it s probably becasue of the name, to do the "read only" use :init_arg :get multivac:~ dmuey$ perl -le 'package X;use Class::Std; { my %x : ATTR(:init_arg<foo> :get<foo>) }package main;my $x=X->new({foo=>2});print $x->get_foo(); print $x- Show quoted text
>set_foo(3);print $x->get_foo();'
2 Can't locate object method "set_foo" via package "X" at -e line 1 multivac:~ dmuey$