Here is what I ended up with after the fix using the proper methods.  I
intercepted the response and will process it chunk by chunk because the
returns from the database can get pretty LARGE (note LIMIT of 5 Billion
records in query)...There will be some additional processing that has to
get done on the query response (converted from either NT or CSV to JSON for
visualization).  Is there a more efficient way of doing it than what I
have?  Bear in mind, in most cases, result sets will be no more than a few
thousand rows....but for those occasions where it is not, I wanted a way to
ensure that I don't overload the system/memory/other library with a huge
object to be converted...so I figure that doing it on the fly was best.

Your thoughts?

#!/usr/bin/env perl

use strict;
use warnings;
use 5.016;
use Carp qw(cluck carp croak);
use Data::Dumper;
use File::Tail;
use Proc::ProcessTable;
use Mojolicious;
use Mojo::UserAgent;
use Mojo::UserAgent::CookieJar;

my $h = 'someHost';
my $ua = Mojo::UserAgent->new;
$ua->inactivity_timeout(600);
my $jar = Mojo::UserAgent::CookieJar->new;

if(doLogin($h,'user','pass)) {
    my $query = <<QUERY;
    CONSTRUCT {
        ?s ?p ?o .
    }
    WHERE {
      ?s ?p ?o .
    }
    LIMIT 5000000000
QUERY

    my $tx = $ua->build_tx(POST => 'someHost' => 'form' => {'query' =>
$query, 'output' => 'nt'});

    $tx->res->content->unsubscribe('read')->on(read => sub {
        my ($content, $bytes) = @_;
        chomp $bytes;
        print $bytes;
    });
    $ua->start($tx);
}

sub doLogin {
    my ($host,$user,$pass) = @_;
    my $loginUrl = 'https://'.$host.'/dologinCmd.html';
    my $tx = $ua->post($loginUrl => 'form' => {'httpd_username' => $user,
'httpd_password' => $pass});

    if(defined $tx->res->content->headers->location and
$tx->res->content->headers->location eq '/success.html') {
        $jar->extract($tx);
        return 1;
    }
    return 0;
}


On Fri, Jun 20, 2014 at 10:33 AM, M. Aaron Bossert <[email protected]>
wrote:

> Gotcha!  I was not aware of that.
>
> Aaron
>
> > On Jun 20, 2014, at 9:31, Abhijit Menon-Sen <[email protected]> wrote:
> >
> > At 2014-06-20 09:21:44 -0400, [email protected] wrote:
> >>
> >> Sebastian,
> >>
> >> OK, I'll bite!  How should I access the headers?
> >
> > Don't bite, just get the Mojo::Headers object via $req->headers and then
> > use the methods described in the Mojo::Headers documentation.
> >
> > -- ams
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Mojolicious" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at http://groups.google.com/group/mojolicious.
> > For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to