Skip to content

Commit

Permalink
use a different example for application specific plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 7, 2014
1 parent e127465 commit 01d9592
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions lib/Mojo/JSON.pm
Expand Up @@ -218,8 +218,7 @@ sub _decode_value {
}

sub _encode_array {
my $array = shift;
return '[' . join(',', map { _encode_value($_) } @$array) . ']';
'[' . join(',', map { _encode_value($_) } @{$_[0]}) . ']';
}

sub _encode_object {
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/JSON/Pointer.pm
@@ -1,8 +1,6 @@
package Mojo::JSON::Pointer;
use Mojo::Base -base;

use Scalar::Util 'looks_like_number';

has 'data';

sub contains { shift->_pointer(1, @_) }
Expand All @@ -23,7 +21,7 @@ sub _pointer {
if (ref $data eq 'HASH' && exists $data->{$p}) { $data = $data->{$p} }

# Array
elsif (ref $data eq 'ARRAY' && looks_like_number($p) && @$data > $p) {
elsif (ref $data eq 'ARRAY' && $p =~ /^\d+$/ && @$data > $p) {
$data = $data->[$p];
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -60,8 +60,7 @@ sub extract_start_line {
return undef unless $$bufref =~ s/^\s*(.*?)\x0d?\x0a//;

# We have a (hopefully) full request line
$self->error({message => 'Bad request start line', advice => 400})
and return undef
return !$self->error({message => 'Bad request start line', advice => 400})
unless $1 =~ $START_LINE_RE;
my $url = $self->method($1)->version($3)->url;
return !!($1 eq 'CONNECT' ? $url->authority($2) : $url->parse($2));
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Message/Response.pm
Expand Up @@ -95,7 +95,7 @@ sub extract_start_line {

# We have a full response line
return undef unless $$bufref =~ s/^(.*?)\x0d?\x0a//;
$self->error({message => 'Bad response start line'}) and return undef
return !$self->error({message => 'Bad response start line'})
unless $1 =~ m!^\s*HTTP/(\d\.\d)\s+(\d\d\d)\s*(.+)?$!;

my $content = $self->content;
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Server/CGI.pm
Expand Up @@ -26,18 +26,17 @@ sub run {
# Response start line
STDOUT->autoflush(1);
binmode STDOUT;
my $res = $tx->res;
my $res = $tx->res->fix_headers;
return undef if $self->nph && !_write($res, 'get_start_line_chunk');

# Response headers
$res->fix_headers;
my $code = $res->code || 404;
my $msg = $res->message || $res->default_message;
$res->headers->status("$code $msg") unless $self->nph;
return undef unless _write($res, 'get_header_chunk');

# Response body
$tx->is_empty or _write($res, 'get_body_chunk') or return undef;
return undef unless $tx->is_empty || _write($res, 'get_body_chunk');

# Finish transaction
$tx->server_close;
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Server/PSGI.pm
Expand Up @@ -21,10 +21,9 @@ sub run {
$self->emit(request => $tx);

# Response headers
my $res = $tx->res->fix_headers;
my $headers = $res->headers;
my $res = $tx->res->fix_headers;
my $hash = $res->headers->to_hash(1);
my @headers;
my $hash = $headers->to_hash(1);
for my $name (keys %$hash) {
push @headers, map { $name => $_ } @{$hash->{$name}};
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1234,9 +1234,10 @@ L<Mojolicious::Plugin>.

sub register {
my ($self, $app) = @_;
$app->helper(info => sub {
my ($c, $str) = @_;
$c->app->log->info($str);
$app->helper(render_with_header => sub {
my ($c, @args) = @_;
$c->res->headers->header('X-Mojo' => 'I <3 Mojolicious!')
$c->render(@args);
});
}

Expand All @@ -1254,8 +1255,7 @@ name.

get '/' => sub {
my $c = shift;
$c->info('I ♥ Mojolicious!');
$c->render(text => 'Hello.');
$c->render_with_header(text => 'I ♥ Mojolicious!');
};

app->start;
Expand Down
8 changes: 3 additions & 5 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -40,11 +40,9 @@ sub _html {
# Rewrite links
my $dom = Mojo::DOM->new(_pod_to_html($src));
my $perldoc = $c->url_for('/perldoc/');
for my $e ($dom->find('a[href]')->each) {
my $attrs = $e->attr;
$attrs->{href} =~ s!::!/!gi
if $attrs->{href} =~ s!^http://metacpan\.org/pod/!$perldoc!;
}
$_->{href} =~ s!^http://metacpan\.org/pod/!$perldoc!
and $_->{href} =~ s!::!/!gi
for $dom->find('a[href]')->attr->each;

# Rewrite code blocks for syntax highlighting and correct indentation
for my $e ($dom->find('pre > code')->each) {
Expand Down

0 comments on commit 01d9592

Please sign in to comment.