[Catalyst] html-widget test prereq

Matt S Trout dbix-class at trout.me.uk
Mon Mar 13 13:24:15 CET 2006


Carl Franks wrote:
> In the html-widget test suite, instead of having this copy-pasted in many files,
> 
> my $query = Test::MockObject->new;
>     my $data = { foo => 'foo', bar => [ 'yada', 23 ] };
>     $query->mock( 'param',
>        sub {
>            my ( $self, $param ) = @_;
>            if ( @_ == 1 ) { return keys %$data }
>            else {
>                unless ( exists $data->{$param} ) {
>                    return wantarray ? () : undef;
>                }
>                if ( ref $data->{$param} eq 'ARRAY' ) {
>                    return (wantarray)
>                      ? @{ $data->{$param} }
>                      : $data->{$param}->[0];
>                }
>                else {
>                    return (wantarray)
>                      ? ( $data->{$param} )
>                      : $data->{$param};
>                }
>            }
>        }
>     );
> 
> Considering CGI.pm has been a core module since perl 5.004, how about
> we just do this instead?
> 
> my $query = CGI->new;
> $query->param( foo => 'foo' );
> $query->param( bar => [ 'yada', 23 ] );

How about just adding a t/lib and loading convenience functions out of that? 
then you could simply do something like

my $query = HTMLWidget::TestLib->mock_query($data);

(and remember to break up the package line to hide it from PAUSE)

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list