This document discusses using Perl to access web APIs. It provides examples of popular web APIs like Twitter, Google, and Flickr. It explains that web APIs use HTTP, URIs, and return formats like JSON and XML. The document then demonstrates how to use Perl modules like LWP, URI, and JSON to make requests to the Twitter Search API, handle UTF-8 encoding, and parse the JSON response. Finally, it mentions more advanced modules for web services in Perl like WebService::Simple.
This document summarizes a presentation about a new way of developing Perl applications and the future of gperl, a fast Perl-like language. It discusses compiler modules for lexical analysis, parsing, and code generation that were originally developed for gperl and can now be used to build various tools and applications. These include a transpiler to run Perl 5 code in web browsers, a framework called PerlMotion for building iOS and OSX apps with Perl, and a static analysis tool for detecting copied code. The presentation encourages contributions to related open source projects and outlines plans to expand the capabilities of the static analysis and type inference engines.
15. package MyClass;
use Mojo::Base -base;
has some_attr => '';
package main;
my $instance = MyClass->new(%hash);
my $instance = MyClass->new($hash_ref);
say $instance->some_attr; # ''
$instance->some_attr('a');
say $instance->some_attr; # 'a'
16. package MyClass; hasと揖じ
use Mojo::Base -base;
__PACKAGE__->attr(some_attr => '');
package main;
my $instance = MyClass->new(%hash);
my $instance = MyClass->new($hash_ref);
say $instance->some_attr; # ''
$instance->some_attr('a');
say $instance->some_attr; # 'a'
17. ☆廣) 兜豚、魯好ラ`のみ
has 'name';
has name => 'foo';
has name => sub {...};
☆廣) コ`ドリファレンスが
兜豚、砲覆誑Uではない
30. 庄稼糸艶恰.鞄岳馨鉛を温頼するのに
around_dispatchフックを喘いる
#!/usr/bin/env perl
use Mojolicious::Lite;
app->hook(around_dispatch => sub {
my ($next, $c) = @_;
## pre process
$next->();
## post process
});
app->start;
31. リクエストパスを温頼するのに
around_dispatchフックを喘いる
app->hook(around_dispatch => sub {
my ($next, $c) = @_;
## pre process
$next->();
## post process
});
Plack::Middlewareに貌てる
32. index.htmlをa頼する
app->hook(around_dispatch => sub {
my ($next, $c) = @_;
# auto fill file name
my $path = $c->req->url->path;
if ($path->trailing_slash || ! @{$path->parts}) {
push(@{$path->parts}, 'index.html');
$path->trailing_slash(0);
}
$next->();
## post process
});
app->start;
35. パスをディレクトリA咾Qするル`ト
get '/' => 'index';
get '/index.html' => 'index';
get '/index2.html' => 'index2';
get '/dir/' => 'dir/index';
get '/dir/index.html' => 'dir/index';
get '/dir/index2.html' => 'dir/index2';
36. パスをディレクトリA咾Qするル`ト
# /path/to/index.html
# stash => {
????template => '/path/to/index',
????format => 'html'
}
get '(*template).(*format)' => sub {
my $c = shift;
$c->render;
$c->res->code || $c->render_not_found;
};
37. /index.html.epへのリクエストを403に
app->hook(around_dispatch => sub {
my ($next, $c) = @_;
if ($c->req->url->path =~ qr{.ep$}) {
$c->render_exception('Forbidden');
$c->res->code(403);
return;
}
# auto fill file name
my $path = $c->req->url->path;
if ($path->trailing_slash || ! @{$path->parts}) {
push(@{$path->parts}, 'index.html');
$path->trailing_slash(0);
}
$next->();
});