Last active
February 12, 2016 19:02
-
-
Save preaction/0244d52eab4d445cc4a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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