Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I'm probably over-simplifying your problem, but I think that the solution adopted by DBIx::Class is a nice brain fit. Under Catalyst, I would say something like:

    my $query = $c->model('Entity::Person');
    $query = $query->search({age => ['==', 30]});
    $query = $query->search({mumble...  => ['==', 'Fido']});
    $query = $query->search(undef, {order_by => 'name ASC'});
    my $adam = $query->first;

    where I don't know how to write the "mumble" part off the top of my head, but it's probably acc

    • Unfortunately, yes this oversimplifies the problem.

      It solves the problem by getting rid of the class tree altogether and using Perl structures.

      Here's another example of the sort of stuff I'm doing.

      # We need a certain type of person
      my $query = MyApp::Entity::Person->Fetch;
      $query->condition('OptimizedFor', '==', 'fun');
                      MyApp::SQL::Clause->new('Lame', 'is null'),
                      MyApp::SQL::Clause->new('Age', 'new('Name', '!in', 'Adam', 'Bob', 'Whatever'),

      # What projects are they in
      my $projects = $query->traverse('FoundedProjects');
      my @projects = $projects->fetch( $dbh );

      # Lets save that query so we can send it to bob,
      # who is using the same application, but with Oracle.
      $projects->save_as( 'WatchList.dat' );

      As you can see, the SQL objects not only let me build up arbitrary nested structures, and create new queries with existing ones as subselects/joins, but the queries also serialize to a logical form, regardless of the database they will be executed on.

      So it's basically an abstract tree for the queries of various types, that ignores the actual table names and column names (which might vary) and ignores the implementation method (for example, on Oracle, limit is implemented via a subselect).

      This is where the main issue of Tree + Driver kicks in...
      • Ack, my "less than" condition in the nested structure broke it :(

        But you get the point.