On 10/19/2011 07:04 PM, David Christensen wrote:
> I am looking for a class that stores zero or more items (e.g. a list)
> and that provides accessors that accept and return scalar, list,
> and/or array references depending upon context and object content
> (similar to CGI.pm, but not exactly the same):
> use WishfulThinkingListClass;
> my $o = WishfulThinkingListClass->new();
> $o->set('foo'); # saves one-item list
> my $v = $o->get(); # returns scalar 'foo'
> my @v = $o->get(); # returns one-item list ('foo')
> $o->set('bar', 'baz'); # saves two-item list
> $v = $o->get(); # returns arrayref ['bar', 'baz']
> @v = $o-get(); # returns list ('bar', 'baz')
> $o->set(['bozo']); # saves one-item list
> In addition to "set", "get", I can envision instance methods
> "mypush", "mypop", "myshift", and "myunshift".
> Is there such an thing in standard Perl (5.10.1) or on CPAN?
On 10/20/2011 07:27 AM, Randal L. Schwartz wrote:
With the right amount of definitions, I did something exactly like this
with Moose. Unfortunately, the actual code is at $former_client's SVN,
so I can't pull it out just now.
Thank you for your reply, and thank you for your contributions to Perl. :-)
I've also built something similar, in the form of a data structure (hash
of WishfulThinkingListClass'es) that I use for holding arguments to
CGI::header(). I was hoping for an existing general-purpose type that I
could use and/or extend as required (such as arguments to CGI::redirect()).
What would be a suitable name for this type?
David
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/