Skip to content

Commit

Permalink
added content generator recipe to cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 12, 2013
1 parent dc9b3a4 commit 2a42051
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -909,6 +909,7 @@ And once again you don't have to worry about memory usage, all data will be
streamed directly from the file.

use Mojo::UserAgent;
use Mojo::Asset::File;

# Upload file via PUT
my $ua = Mojo::UserAgent->new;
Expand Down Expand Up @@ -975,6 +976,25 @@ be able to work standalone as well as inside L<Mojolicious> applications.
$ua->get('http://mojolicio.us/perldoc' => $delay->begin);
$delay->wait unless Mojo::IOLoop->is_running;

=head2 Content generators

To generate the same type of content repeatedly for multiple requests, you can
use L<Mojo::UserAgent::Transactor> generators.

use Mojo::UserAgent;
use Mojo::Asset::File;

# Add "large" generator
my $ua = Mojo::UserAgent->new;
$ua->transactor->add_generator(large = sub {
my ($transactor, $tx, $path) = @_;
$tx->req->content->asset(Mojo::Asset::File->new(path => $path));
});

# Upload multiple files streaming via PUT
$ua->put('http://mojolicio.us/upload' => large => '/home/sri/mojo.png');
$ua->put('http://mojolicio.us/upload' => large => '/home/sri/mango.png');

=head2 Command line

Don't you hate checking huge HTML files from the command line? Thanks to the
Expand Down

0 comments on commit 2a42051

Please sign in to comment.