5. use HTTP::ProxyPAC;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $uri = URI->new(quot;http://portal.titech.ac.jp/proxy.pacquot;);
my $pac = HTTP::ProxyPAC->new($uri);
my $res = $pac->find_proxy(quot;http://www.google.com/quot;);
if ($res->direct) {
# ...
} elsif ($res->proxy) {
$ua->proxy('http' => $res->proxy);
}
6. use JavaScript::Runtime;
sub init {
my($class, $code) = @_;
my $runtime = JavaScript::Runtime->new;
my $context = $runtime->create_context();
for my $func (@HTTP::ProxyPAC::Functions::PACFunctions) {
no strict 'refs';
$context->bind_function(
name => $func,
func => sub { &{quot;HTTP::ProxyPAC::Functions::$funcquot;}(@_) });
}
$context->eval($code);
bless { context => $context }, $class;
}
7. package HTTP::ProxyPAC::Functions;
# stolen from HTTP::ProxyAutoConfig
sub isPlainHostName {
my ($host) = @_;
return (($host =~ /./) ? 0 : 1);
}
sub dnsResolve {
my ($host) = @_;
return unless isResolvable($host);
return inet_ntoa(inet_aton($host));
}
sub myIpAddress {
return inet_ntoa(inet_aton(hostname()));
}
11. use pQuery::DOM;
my $v = pQuery::DOM->fromHTML('<div id=quot;fooquot;>bar</div>')
->getElementById('foo')->innerHTML;
12. use pQuery::DOM;
no capitalization ‘pQuery::DOM’;
my $v = pQuery::DOM->fromHTML('<div id=quot;fooquot;>bar</div>')
->get_element_by_id('foo')->innerHTML;
18. use PHP::Session;
my $session = PHP::Session->new($id);
# session id
my $id = $session->id;
# get/set session data
my $foo = $session->get('foo');
$session->set(bar => $bar);
42. my $latin1_as_utf8 = quot;[xC2xC3][x80-xBF]quot;;
my $valid_utf8_regexp = <<'.' ;
[x{00}-x{7f}]
| [x{c2}-x{df}][x{80}-x{bf}]
| x{e0} [x{a0}-x{bf}][x{80}-x{bf}]
| [x{e1}-x{ec}][x{80}-x{bf}][x{80}-x{bf}]
| x{ed} [x{80}-x{9f}][x{80}-x{bf}]
| [x{ee}-x{ef}][x{80}-x{bf}][x{80}-x{bf}]
| x{f0} [x{90}-x{bf}][x{80}-x{bf}]
| [x{f1}-x{f3}][x{80}-x{bf}][x{80}-x{bf}][x{80}-x{bf}]
| x{f4} [x{80}-x{8f}][x{80}-x{bf}][x{80}-x{bf}]
.
sub decode {
my($obj, $buf, $chk) = @_;
$buf =~ s{((?:$latin1_as_utf8){2,3})}{ _check_utf8_bytes($1) }ego;
$_[1] = '' if $chk; # this is what in-place edit means
Encode::decode_utf8($buf);
}
sub _check_utf8_bytes {
my $bytes = shift;
my $copy = $bytes;
my $possible_utf8 = '';
while ($copy =~ s/^(.)(.)//) {
$possible_utf8 .= chr( (ord($1) << 6 & 0xff) | ord($2) )
}
$possible_utf8 =~ /$valid_utf8_regexp/xo ? $possible_utf8 : $bytes;
}
46. use utf8;
use URI::Find;
my $text = <<TEXT;
Japanese Wikipedia home page URL is
http://ja.wikipedia.org/wiki/
TEXT
my $finder = URI::Find->new(&cb);
$finder->find($text);
sub cb { warn shift }
# http://ja.wikipedia.org/wiki/
47. use utf8;
use URI::Find::UTF8;
my $text = <<TEXT;
Japanese Wikipedia home page URL is
http://ja.wikipedia.org/wiki/
TEXT
my $finder = URI::Find::UTF8->new(&cb);
$finder->find($text);
sub cb {
my($uri, $orig) = @_;
}
# http://ja.wikipedia.org/wiki/