Created
February 7, 2012 08:27
-
-
Save phluks/1758245 to your computer and use it in GitHub Desktop.
Mojo - add condition
This file contains 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
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