FAQ
Hi,

We have a growing mismatch in our code between methods that return
ResultSet objects and those that return an array/arrayref of objects.
This is in a Catalyst model layer.

For the sake of api consistency I'd like to have a fake ResultSet class
that had the same api, but was just seeded with a list of objects.

ResultSet::Fake->new({ records => [@records] });

But I expect this wouldn't play well with the forthcoming release.

Is there a common solution to this problem? How do people keep their api
consistent?

Thanks, Richard

Search Discussions

  • Matt S Trout at Jan 25, 2006 at 5:47 pm

    On Wed, Jan 25, 2006 at 03:00:58PM -0000, Richard Jolly wrote:
    Hi,

    We have a growing mismatch in our code between methods that return
    ResultSet objects and those that return an array/arrayref of objects.
    This is in a Catalyst model layer.

    For the sake of api consistency I'd like to have a fake ResultSet class
    that had the same api, but was just seeded with a list of objects.

    ResultSet::Fake->new({ records => [@records] });

    But I expect this wouldn't play well with the forthcoming release.

    Is there a common solution to this problem? How do people keep their api
    consistent?
    You could provide a fake object that just returns things as ->next is called
    on it fairly trivially, but I'm not sure that's the ideal solution.

    What sort of objects are ending up in @records? I wonder if you mightn't be
    able to return a proper resultset for the query as of 0.05 unless it's a
    really insane one :)

    --
    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/ +
  • Richard Jolly at Jan 25, 2006 at 6:15 pm

    From: dbix-class-bounces@lists.rawmode.org
    On Behalf Of
    Matt S Trout
    Sent: 25 January 2006 17:05
    To: dbix-class@lists.rawmode.org
    Subject: Re: [Dbix-class] faking ResultSets
    On Wed, Jan 25, 2006 at 03:00:58PM -0000, Richard Jolly wrote:
    Hi,

    We have a growing mismatch in our code between methods that return
    ResultSet objects and those that return an array/arrayref
    of objects.
    This is in a Catalyst model layer.
    [snip]
    Is there a common solution to this problem? How do people
    keep their api consistent?
    You could provide a fake object that just returns things as
    ->next is called on it fairly trivially, but I'm not sure
    that's the ideal solution.

    What sort of objects are ending up in @records? I wonder if
    you mightn't be able to return a proper resultset for the
    query as of 0.05 unless it's a really insane one :)
    I hope so, but we've not yet played with the new stuff. We do have a
    particurlarly nasty schema. I'll see if I can put together an example.

    But even in some trivial cases - for lists outside of the model classes
    for example - it might be nice to unify the interface. Otherwise people
    using template toolkit have to know what kind of list they've got in
    order to be able to treat it sensibly.

    Thanks for the fantastic work, BTW.

    Richard
    --
    Matt S Trout Offering custom development,
    http://www.bbc.co.uk/

    This e-mail (and any attachments) is confidential and may contain
    personal views which are not the views of the BBC unless specifically
    stated.
    If you have received it in error, please delete it from your system.
    Do not use, copy or disclose the information in any way nor act in
    reliance on it and notify the sender immediately. Please note that the
    BBC monitors e-mails sent or received.
    Further communication will signify your consent to this.
  • David Jack Olrik at Jan 26, 2006 at 8:56 am

    On 25/01/2006, at 16.00, Richard Jolly wrote:

    We have a growing mismatch in our code between methods that return
    ResultSet objects and those that return an array/arrayref of objects.
    This is in a Catalyst model layer.

    Is there a common solution to this problem? How do people keep
    their api
    consistent?
    What about http://search.cpan.org/~mramberg/DBIx-Class-AlwaysRS-0.01/

    --
    Best regards,
    David Jack Olrik <david@olrik.dk> http://david.olrik.dk
    GnuPG fingerprint C290 0A4A 0CCC CBA8 2B37 E18D 01D2 F6EF 2E61 9894
    ["The first rule of Perl club is You do not talk about Perl club"]
  • Richard Jolly at Jan 26, 2006 at 12:36 pm

    From: dbix-class-bounces@lists.rawmode.org
    On Behalf Of
    David Jack Olrik
    Sent: 26 January 2006 08:03
    On 25/01/2006, at 16.00, Richard Jolly wrote:

    We have a growing mismatch in our code between methods that return
    ResultSet objects and those that return an array/arrayref
    of objects.
    This is in a Catalyst model layer.

    Is there a common solution to this problem? How do people
    keep their
    api consistent?
    What about http://search.cpan.org/~mramberg/DBIx-Class-AlwaysRS-0.01/
    That's nice, particularly for the TT problem. But it doesn't quite
    address my original issue:

    sub foo {
    ...
    return Class->search(...);
    }

    sub bar {
    ... do some non-DBIC stuff ...
    return wantarray ? @stuff : \@stuff;
    }

    Consistency is good.

    Richard
    --
    Best regards,
    David Jack Olrik <david@olrik.dk> http://david.olrik.dk
    http://www.bbc.co.uk/

    This e-mail (and any attachments) is confidential and may contain
    personal views which are not the views of the BBC unless specifically
    stated.
    If you have received it in error, please delete it from your system.
    Do not use, copy or disclose the information in any way nor act in
    reliance on it and notify the sender immediately. Please note that the
    BBC monitors e-mails sent or received.
    Further communication will signify your consent to this.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbix-class @
categoriesperl, catalyst
postedJan 25, '06 at 4:00p
activeJan 26, '06 at 12:36p
posts5
users3
websitedbix-class.org
irc#dbix-class

People

Translate

site design / logo © 2022 Grokbase