Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active February 12, 2016 19:02
Show Gist options
  • Save preaction/0244d52eab4d445cc4a7 to your computer and use it in GitHub Desktop.
Save preaction/0244d52eab4d445cc4a7 to your computer and use it in GitHub Desktop.
use trap;
trap ( qr{Out of memory} ) {
$big_data = undef;
return main(); # Try again
}
trap ( $_->isa( 'HTTP::Response' ) && $_->code != 200 ) {
return error_page( $_ );
}
sub send_data {
my ( $data ) = @_;
return post( '/upload', $data );
}
sub post {
my $resp = send_request( @_ );
if ( $resp->code != 200 ) {
# Trap is run because of die(). Return value from trap is returned from
# this function instead
die $resp;
}
return $resp;
}
sub main {
my $big_data = get_data;
print send_data( $big_data );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment