Skip to content

Instantly share code, notes, and snippets.

@phluks
Created February 7, 2012 08:27
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 phluks/1758245 to your computer and use it in GitHub Desktop.
Save phluks/1758245 to your computer and use it in GitHub Desktop.
Mojo - add condition
Ah, I think I found out. I need to use a bridge for this.
# Can this be implemented with a Mojo-lite thingy?
# This is my problem:
sub startup {
my $self = shift;
# JSON Errors - you may want to uncomment for debug
#$self->controller_class("BIER::SERVICES::Errors::Json");
# THIS GETS PRINTED
print STDERR "startup\n";
# "build-in" route
my $r = $self->routes;
$r->add_condition(
agent => sub {
my ($r, $c, $captures, $pattern) = @_;
# !!! DOES NOT GET PRINTED
print STDERR "In add_condition\n";
my $accept = $c->req->headers->accept;
if ($accept eq "application/vnd.yousee.bier+json;version=1;charset=UTF-8") {
# ok
print STDERR "Accept OK: $accept\n";
return 1;
} else {
# not ok
print STDERR "Accept not OK: $accept\n";
return;
}
});
# This route is accessable - no matter what header or not I set.
$r->get('/alive' => sub {
my $self = shift;
$self->render_json({text => "activity", success => 'Yes'});
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment