Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Deep CPAN distribution.

Report information
The Basics
Id: 5869
Status: resolved
Priority: 0/
Queue: Test-Deep

People
Owner: Nobody in particular
Requestors: ilya [...] martynov.org
Cc:
AdminCc:

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



Subject: Using methods() for methods returning lists
First of all thank you for your extreamly useful module. I've started to use it and it rocks. I have one feature request though: it would be nice to allow doing methods()-like tests on methods which return lists. Currenly as quick hack I use following code: sub methods_list { return MyTest::Deep::MethodsList->new(@_); } package MyTest::Deep::MethodsList; use base qw(Test::Deep::Methods); use Test::Deep::Cmp; sub descend { my $self = shift; my $got = shift; my $data = $self->data; foreach my $method (@{$self->{methods}}) { $data->{method} = $method; my ($call, $exp_res) = @$method; my ($name, @args) = @$call; # until this point it was a copy any paste from # Test::Deep::Methods my $got_res = UNIVERSAL::can($got, $name) ? [ $got->$name(@args) ] : $Test::Deep::DNE; # ^^^^ ^^^^^ next if Test::Deep::descend($got_res, $exp_res); return 0; } return 1; }
thanks, glad you like it. This has been on the todo list for a long time but I haven't really needed it myself. I'm not quite sure about the interface. What would you think of this scheme... Retain the normal argument types of Method => 'value' # simple ['method', 'arg1', 'arg2'] # pass args in scalar context and add something like genmethod('method', Args => [], Context => 'list', Result =>[...] ) Context could be 'list', 'scalar' or 'void' (from perlsub manpage) and anything else that might come along in the future. It's quite verbose so I could also add listmethod('Method1', \@result, \@args); listmethod('Method1', \@result); # no arguments to be a shorthand for the common cases. The whole thing still ends up a bit verbose methods( Method1 => 'string or list', listmethod('Method1', ['string', 'or', 'list']) ) but I prefer to signal that a particular method requires special handling rather than have to put all my list context methods in methods_list() and all my scalars in methods(). What do you think? F [guest - Thu Apr 1 06:02:03 2004]: Show quoted text
> First of all thank you for your extreamly useful module. I've started > to use it and it rocks. > > I have one feature request though: it would be nice to allow doing > methods()-like tests on methods which return lists. Currenly as quick > hack I use following code: > > sub methods_list { > return MyTest::Deep::MethodsList->new(@_); > } > > package MyTest::Deep::MethodsList; > > use base qw(Test::Deep::Methods); > > use Test::Deep::Cmp; > > sub descend > { > my $self = shift; > my $got = shift; > > my $data = $self->data; > > foreach my $method (@{$self->{methods}}) { > $data->{method} = $method; > > my ($call, $exp_res) = @$method; > my ($name, @args) = @$call; > > # until this point it was a copy any paste from > # Test::Deep::Methods > my $got_res = UNIVERSAL::can($got, $name) ? [ $got-
> >$name(@args) ] : $Test::Deep::DNE;
> # ^^^^ > ^^^^^ > > next if Test::Deep::descend($got_res, $exp_res); > > return 0; > } > > return 1; > }