Skip to content

Instantly share code, notes, and snippets.

@juster
Created August 19, 2010 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juster/537061 to your computer and use it in GitHub Desktop.
Save juster/537061 to your computer and use it in GitHub Desktop.
sub foobar
{
my ( $cgi ) = @_;
my $data = {};
my $store = sub {
my $name = shift;
return $data->{ $name } = $cgi->param( $name );
};
die "or something" unless $store->( 'request_id' );
my $entry = sub {
my ( $name, $code_ref ) = @_;
return ( $name => sub {
return 0 unless defined $store->( $name );
$code_ref->( $data );
my $reqid = $data->{ 'request_id' };
$output .= $cgi->h2( "Request #" . $reqid )
. $cgi->div( $reqid );
return 1
} );
};
my %code_for = ( $entry->( 'status',sub {
$store->( $_ ) for qw/ program notes /;
create_new_request_status( shift );
} ),
$entry->( 'barcode', \&update_request_barcode ),
$entry->( 'request_name', \&update_request_name ),
$entry->( 'species', \&update_request_species ),
# ...
);
PARAM_LOOP:
for my $name ( keys %code_for ) {
last PARAM_LOOP if $code_for{ $pname }->();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment