Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 63517
Status: rejected
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

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



Subject: hook for package to describe attributes
Date: Thu, 02 Dec 2010 09:06:40 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
I saw in the Class::MOP::Class that attributes in a target class can't be found automatically. Is there a hook or something that a target class can define to describe itself? I thought maybe of a package variable, or maybe a whole file like Class::MOP::Class::AutoInfo::Foo::Bar which Foo::Bar might supply if its info was big or ugly or rarely wanted. It wouldn't make Foo::Bar depend on Class::MOP as such, just be a bit of optional inter-operation. I merely wanted to find out if certain parameters existed to a new() -- on some of my own plain perl5 classes (no moose or anything) -- and before doing something specific I wondered if there was an info format recognised by external introspecting packages. (Class::MOP is almost the only plain perl5 introspector is it?, outside the full oop-ery frameworks ...).
On Wed Dec 01 17:07:48 2010, user42@zip.com.au wrote: Show quoted text
> I saw in the Class::MOP::Class that attributes in a target class can't > be found automatically. Is there a hook or something that a target > class can define to describe itself? > > I thought maybe of a package variable, or maybe a whole file like > Class::MOP::Class::AutoInfo::Foo::Bar which Foo::Bar might supply if its > info was big or ugly or rarely wanted. It wouldn't make Foo::Bar depend > on Class::MOP as such, just be a bit of optional inter-operation. > > I merely wanted to find out if certain parameters existed to a new() -- > on some of my own plain perl5 classes (no moose or anything) -- and > before doing something specific I wondered if there was an info format > recognised by external introspecting packages. (Class::MOP is almost > the only plain perl5 introspector is it?, outside the full oop-ery > frameworks ...).
Since Perl has no notion of an attribute built in, there's really no way to do this. The best you can do is provide an API for a class to describe itself, which is exactly what Class::MOP already does.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Wed, 26 Jan 2011 11:16:15 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > The best you can do is provide an API for a class to describe itself, > which is exactly what Class::MOP already does.
No, but how the class can communicate its fields to Class::MOP. I may end up with moose, though it's a huge amount to drag in just to give a few characteristics of parameters, which may only sometimes be queried.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Tue, 25 Jan 2011 22:24:16 -0600 (CST)
To: Kevin Ryde via RT <bug-Class-MOP [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Tue, 25 Jan 2011, Kevin Ryde via RT wrote: Show quoted text
> Queue: Class-MOP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=63517 > > > "Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes:
>> >> The best you can do is provide an API for a class to describe itself, >> which is exactly what Class::MOP already does.
> > No, but how the class can communicate its fields to Class::MOP.
Yes, and we _already have an API for that_. Class::MOP::Class->initialize(__PACKAGE__)->add_attribute( ... ); -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Ok, after some discussion in #moose I think I understand what you want. Matt Trout suggests you look at Moo and bug him to add the feature you want. While in theory we could add this to CMOP itself, it seems like a bunch of work for not that much gain. Basically everyone using CMOP is using Moose, and they're declaring attributes as part of their class definition, not just to provide meta-information.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Sat, 29 Jan 2011 09:41:50 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"autarch@urth.org via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > Class::MOP::Class->initialize(__PACKAGE__)->add_attribute( ... );
Where may a package Foo::Bar do that, to advertise its attributes? I known there's no strong built-in notion of attribute, but I have in mind making Foo::Bar cooperate with Class::MOP so as to describe itself if requested.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Sat, 29 Jan 2011 09:45:57 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Oops, I followed up to the first bit which was answered by the second bit! :-) "Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > everyone using CMOP is using Moose,
Ah, right. Show quoted text
> bunch of work for not that much gain
Maybe as easy as calling a $package->Class_MOP_Class_initialize, as a bit of a hook, if a given package cared to write some code. I suppose it wouldn't help very much if only a few packages ever did it.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Fri, 28 Jan 2011 20:45:35 -0500
To: bug-Class-MOP [...] rt.cpan.org
From: Stevan Little <stevan.little [...] iinteractive.com>
On Jan 28, 2011, at 5:45 PM, Kevin Ryde via RT wrote: Show quoted text
> Queue: Class-MOP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=63517 > > > Oops, I followed up to the first bit which was answered by the second > bit! :-) > > "Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes:
>> >> everyone using CMOP is using Moose,
> > Ah, right. >
>> bunch of work for not that much gain
> > Maybe as easy as calling a $package->Class_MOP_Class_initialize, as a > bit of a hook, if a given package cared to write some code. I suppose > it wouldn't help very much if only a few packages ever did it. >
How is that all that much different then Class::MOP::Class- Show quoted text
>initialize( $package ) ?
Also, how would you propose telling Class::MOP::Class about the attributes? And why is the ->add_attribute method and Class::MOP::Attribute class not sufficient for your needs? - Stevan
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Fri, 28 Jan 2011 22:32:48 -0600 (CST)
To: Stevan Little via RT <bug-Class-MOP [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Fri, 28 Jan 2011, Stevan Little via RT wrote: Show quoted text
> How is that all that much different then Class::MOP::Class-
> >initialize( $package ) ?
Stevan, what he wants is a hook that is called when some other caller tries to initialize the metaclass for his package. In other words, he wants lazy metaclass population. (I think) -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Fri, 28 Jan 2011 22:35:30 -0600
To: "autarch [...] urth.org via RT" <bug-Class-MOP [...] rt.cpan.org>
From: Jesse Luehrs <doy [...] tozt.net>
On Fri, Jan 28, 2011 at 11:32:57PM -0500, autarch@urth.org via RT wrote: Show quoted text
> Queue: Class-MOP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=63517 > > > On Fri, 28 Jan 2011, Stevan Little via RT wrote: >
> > How is that all that much different then Class::MOP::Class-
> > >initialize( $package ) ?
> > Stevan, what he wants is a hook that is called when some other caller > tries to initialize the metaclass for his package. In other words, he > wants lazy metaclass population. > > (I think)
As Matt Trout brought up on IRC, what's wrong with this? sub meta { my $self = shift; require Class::MOP; my $meta = Class::MOP::Class->initialize(blessed($self) || $self); $meta->add_attribute(...); return $meta; } -doy
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Wed, 02 Feb 2011 11:45:47 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"autarch@urth.org via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > when some other caller > tries to initialize the metaclass for his package.
Yes, that would be the idea. Show quoted text
> In other words, he wants lazy metaclass population.
Umm, yes, that too, in as much as I don't need meta anything for the simple stuff in my package, it'd only be for others who might enquire. "Jesse Luehrs via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > sub meta { > my $self = shift; > require Class::MOP;
That'd be pretty close. I might experiment with that or a get_attribute_list() or whatever and see how it goes. (If I want to describe "int" or "string" or "min" and "max" range for the attributes then maybe that needs moose or a type system or something anyway ...)
I think Jesse's solution is basically all that's needed, and there's no reason to add something to CMOP itself for this.
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Sat, 26 Feb 2011 09:45:33 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > I think Jesse's solution is basically all that's needed, and there's no > reason to add something to CMOP itself for this.
The docs could note that as one way to do it, or the suggested way to do it. A class method in a package to build a Class::MOP::Class and load up attributes was it?
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Sun, 27 Feb 2011 10:23:14 -0600 (CST)
To: Kevin Ryde via RT <bug-Class-MOP [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Fri, 25 Feb 2011, Kevin Ryde via RT wrote: Show quoted text
> Queue: Class-MOP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=63517 > > > "Dave Rolsky via RT" <bug-Class-MOP@rt.cpan.org> writes:
>> >> I think Jesse's solution is basically all that's needed, and there's no >> reason to add something to CMOP itself for this.
> > The docs could note that as one way to do it, or the suggested way to do > it. A class method in a package to build a Class::MOP::Class and load > up attributes was it?
I think a doc patch would be fine, but I wouldn't want to feature it too prominently. This is not a very common need. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #63517] hook for package to describe attributes
Date: Wed, 02 Mar 2011 09:24:14 +1100
To: bug-Class-MOP [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"autarch@urth.org via RT" <bug-Class-MOP@rt.cpan.org> writes: Show quoted text
> > I think a doc patch would be fine, but I wouldn't want to feature it too > prominently. This is not a very common need.
Maybe under "Attribute introspection and creation" where it says what can't be done, Moose and its family provide a C<CLASS-E<gt>meta()> making a C<$metaclass> with attributes. Non-moose packages could do similar. Plus whatever "other ways to do it" to suggest or cross referencing. (Or Moose is the number 1 ticket holder of all this stuff anyway is it? :-) -- Food jargon elucidated for the layman: "Gourmet selection" -- twice the price.
On Tue Mar 01 17:24:13 2011, user42@zip.com.au wrote: Show quoted text
> "autarch@urth.org via RT" <bug-Class-MOP@rt.cpan.org> writes:
> > > > I think a doc patch would be fine, but I wouldn't want to feature it too > > prominently. This is not a very common need.
> > Maybe under "Attribute introspection and creation" where it says what > can't be done, > > Moose and its family provide a C<CLASS-E<gt>meta()> making a > C<$metaclass> with attributes. Non-moose packages could do > similar. > > Plus whatever "other ways to do it" to suggest or cross referencing. > (Or Moose is the number 1 ticket holder of all this stuff anyway is it? > :-) > >
Was this doc patch produced? Is it still relevant? Marking stalled until these questions, and others that inquiring minds might want to know, are answered. -Chris
I don't think this is relevant anymore.