[Dbix-class] Per the design of a method

Eden Cardim edencardim at gmail.com
Mon Jun 20 20:53:12 GMT 2011


>>>>> "dorian" == dorian taylor <dorian.taylor.lists at gmail.com> writes:

    dorian> On Thu, Jun 16, 2011 at 12:57 PM, Oleg Kostyuk <cub.uanic at gmail.com> wrote:
    >> HTH, but if not, then re-read manuals :)

    dorian> What I want to do is write a method that retrieves a subset of an
    dorian> ordered result set using absolute numbers for the start and end. I
    dorian> also want the count for what would be returned if the subset wasn't
    dorian> specified. For the sake of the method's interface I also want to be
    dorian> able to just pass in a ResultSet object rather than passing in its
    dorian> WHERE clause and attributes and building two separate ResultSets
    dorian> inside the method.

Why don't you make that a method of the resultset?

my $rs_subset = $rs->subset($start, $end);

Then your method can delegate to that if you still need it to be
external for whatever reason:

sub yourmethod {
   my($self, $rs, $start, $end) = @_;
   my $subset_rs = $rs->subset($start, $end);
   # etc...
 }

yourmethod($rs, $start, $end);

    dorian> What I'm saying is that it would be awfully nice to be able to either
    dorian> extract the WHERE clause from the supplied ResultSet so I can clone
    dorian> it

It's even nicer, DBIC already builds clones for you via the search API,
if you want an unmodified clone, just run an empty search, ie:
$rs->search({})

    dorian> or modify the rows/offset attributes, but there doesn't
    dorian> seem to be any way in the DBIx::Class::ResultSet interface
    dorian> to actually do that.

$rs->search({}, { rows => $rows, offset => $offset }); # works for me

    dorian> And I can't think of any way of using Data::Page because it uses
    dorian> multiples

"uses multiples"? what do you mean?

    dorian> unless I do something like set the offset to $x and collect
    dorian> as many pages as $x*$y >= $z, but that is dumb.

Huh?

    dorian> Did I miss something?

Yes, the actual requirement with a use-case and sample code, apparently,
no-one has yet understood how this relates to the rest of what you said
so far.

-- 
   Eden Cardim       Need help with your Catalyst or DBIx::Class project?
  Code Monkey                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://blog.edencardim.com/            http://www.shadowcat.co.uk/servers/
http://twitter.com/#!/edenc



More information about the DBIx-Class mailing list