Beware of classes that export 'retrieve' functions

[prev] [thread] [next] [Date index for 2004/05/13]

From: William McKee
Subject: Beware of classes that export 'retrieve' functions
Date: 02:33 on 13 May 2004
--cmJC7u66zC7hs+87
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I just spent about an hour tracking a problem with one of my projects
which involved a retrieve operation failing with a very bizarre error
message. Turns out that my colleague had used Storable in a subroutine
inside of the package. As I suspect many of you already know, Storable
exports 'retrieve' into the namespace. This was causing my calls to
retrieve() to be handled by Storable thus the errors.

In the process of tracking down the problem, I also had errors with a
search()->delete_all operation. Since I did not see any tests which
explicitly tested the search()->delete_all operation, I wrote a test
case against 0.96 to see if I could replicate the problem which seemed
to stem from deleting multiple objects. I could not replicate the error
and suspect these errors had to do with the problem above. I've attached
the test case to this message should Tony want to add it to the test
suite.


Regards,
William

        -- 
        Knowmad Services Inc.
http://www.knowmad.com

--cmJC7u66zC7hs+87
Content-Type: application/x-troff
Content-Disposition: attachment; filename="23-delete.t"
Content-Transfer-Encoding: quoted-printable

use strict;=0Ause Test::More;=0Ause Data::Dumper;=0A=0ABEGIN {=0A  eval "us=
e DBD::SQLite";=0A  plan $@ ? (skip_all =3D> 'needs DBD::SQLite for testing=
') : (tests =3D> 10);=0A=0A  use lib 't/testlib';=0A  use Film;=0A  use Act=
or;=0A  Film->CONSTRUCT;=0A  Actor->CONSTRUCT;=0A  Film->has_many(actors =
=3D> Actor =3D> 'Film', { order_by =3D> 'name' });=0A  Actor->has_a(Film =
=3D> 'Film');=0A  is(Actor->primary_column, 'id', "Actor primary OK");=0A}=
=0A=0A# Testing multiple delete_all via search=0Aok(=0A  my $agent =3D Acto=
r->create(=0A    {=0A      Name   =3D> 'Agent Smith',=0A      Film   =3D> '=
The Matrix',=0A      Salary =3D> '15_000'=0A    }=0A  ),=0A  'create actor'=
=0A);=0Aok(=0A  my $rc =3D Actor->search(Name =3D> 'Agent Smith')->delete_a=
ll,=0A  'Delete a single entry via search()->delete_all.',=0A);=0A=0Aok(=0A=
  my $agent =3D Actor->create(=0A    {=0A      Name   =3D> 'Agent Smith',=
=0A      Film   =3D> 'Matrix Revolutions',=0A      Salary =3D> '45_000'=0A =
   }=0A  ),=0A  'create actor'=0A);=0A=0Aok(=0A  $agent =3D Actor->create(=
=0A    {=0A      Name   =3D> 'Agent Smith',=0A      Film   =3D> 'The Matrix=
 Reloaded',=0A      Salary =3D> '75_000'=0A    }=0A  ),=0A  'create actor'=
=0A);=0A=0Amy $agent =3D Actor->search(Name =3D> 'Agent Smith');=0Aok(=0A  =
my $rc =3D $agent->delete_all,=0A  'Delete multiple entries via search() th=
en delete_all.',=0A);=0A=0A=0A# Recreate some entries=0Aok(=0A  my $agent =
=3D Actor->create(=0A    {=0A      Name   =3D> 'Lord Elrond',=0A      Film =
  =3D> 'Fellowship of the Ring',=0A      Salary =3D> '145_000'=0A    }=0A  =
),=0A  'create actor'=0A);=0A=0Aok(=0A  $agent =3D Actor->create(=0A    {=
=0A      Name   =3D> 'Lord Elrond',=0A      Film   =3D> 'The Two Towers',=
=0A      Salary =3D> '275_000'=0A    }=0A  ),=0A  'create actor'=0A);=0A=0A=
ok(=0A  $agent =3D Actor->create(=0A    {=0A      Name   =3D> 'Lord Elrond'=
,=0A      Film   =3D> 'Return of the King',=0A      Salary =3D> '475_000'=
=0A    }=0A  ),=0A  'create actor'=0A);=0A=0Aok(=0A  my $rc =3D Actor->sear=
ch(Name =3D> 'Lord Elrond')->delete_all,=0A  'Delete multiple entries via s=
earch()->delete_all.',=0A);=0A
--cmJC7u66zC7hs+87--

Beware of classes that export 'retrieve' functions
William McKee 02:33 on 13 May 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52