Matt Diephouse <[EMAIL PROTECTED]> wrote:
> On Tue, 7 Dec 2004 00:39:08 -0800, Brent 'Dax' Royal-Gordon
> >     my Patient @byid[Int $id] {
> >         select_patients("SELECT * FROM patients WHERE patientid = ?", 
> > $id)[0];
> >     }
> >     multi my Patient %byname{String $last} {
> >         select_patients(
> >             "SELECT * FROM patients WHERE lastname = ?",
> >             $last, $first
> >         );
> >     }
> >     multi my Patient %byname{String $last, String $first} {
> >         select_patients(
> >             "SELECT * FROM patients WHERE lastname = ? AND firstname = ?",
> >             $last, $first
> >         );
> >     }
> >
> >     ...
> > }
> 
> for @byid -> $patient { ... }
> for %byname.kv -> $key, $value { ... }

Point.  Maybe you just have to make all objects handled through this
method multi, though, and provide an empty-arguments variant:

    multi my Patient @byid[] {
        return select_patients("SELECT * FROM patients");
    }

If the underlying code returns lazy lists, this can be a fairly
efficient way to do things.

The usefulness of this might be limited to providing several views an
underlying data (as above), but if you're doing something much more
complicated, chances are you really ought to use a class and an C<is>.

-- 
Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]>
Perl and Parrot hacker

"I might be an idiot, but not a stupid one."
    --c.l.p.misc (name omitted to protect the foolish)

Reply via email to