On 11/18/05, David Baird <[EMAIL PROTECTED]> wrote:
> Well, you can get the list out, munge it using whichever CPAN module,
> then stick it back in. That way, you don't force everybody to interact
> with the list via a fixed API. It's just a list, I can't see a strong
> argument to change it into an object just to make it easier to
> manipulate.
>
First , i dont see making helper methods more helpful or even adding
helper methods as forcing everyone to interact with the list via a
fixed api. I never meant to imply limiting interaction with any list.
I don't see a strong argument for adding extra help here yet either.
However I also think the only strong arg not to would be if we
assumed everyone already has a way to do list subtraction they are
comfortable with. That is false in my case.
I think making helper methods more helpful is not a bad thing. Here'
s my solution .
Allow display_columns and friends to take args:
$self->display_columns() ; # standard
$self->display_columns('-', @list) ; # subtract a few from it
$self->display_columns('minus', @list) ; # subtract a few from it
$self->display_column('+' , @list); # just to round it out
$self->display_column('plus' , @list); # just to round it out
Now that is better than what i am doing now any way.
It depends on a list_diff sub that preserves the order. It is ugly.
Maybe someone can pretty it up for me.. (I could not figure out how to
do a grep within a grep. Is that possible?)
sub _list_diff {
my ($orig, $minus) = @_;
my @new = grep {
my $keep = 1;
foreach my $m (@$minus) {
if ("$_" eq "$m") { $keep = 0; last; }
}
$keep;
} @$orig;
return wantarray ? @new : [EMAIL PROTECTED];
}
Now when i give lists of columns i can easily specify them as a subset
of all columns.
Here is the display_columns sub, which returns a ref in scalar context
as well. That maybe should not do that. I don' t see why not though.
.
sub display_columns {
my ($self, $oper, @list) = @_;
my @all = $self->columns;
return @all unless $oper;
my @subset ;
if ($oper eq '-' || $oper =~ /minus/) {
@subset = _list_diff([EMAIL PROTECTED], [EMAIL PROTECTED]);
}
elsif ($oper eq '+' || $oper =~ /plus/i) {
@subset = (@all, @list);
}
return wantarray ? @subset : [EMAIL PROTECTED]; # why not?
}
Then when I override it I do :
sub display_columns {
my ($self, $oper, @list) = @_;
return $self->SUPER::display_columns unless $oper;
# Ahgg. not as simple to override and keep functionality. :(
....
# damn hard to override :( Taking plus functionality out
might make it easier.
}
OK. well anyway, i'm gonna try that and see how i like it.
cheers.
--
pjs
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_idv28&alloc_id845&op=click
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users