This file contains hidden or 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
sub clean_code($){ | |
for (my $str = shift) { | |
s/<(xml|style)>.*?<\/\1>//sg; | |
s/<!--.*?-->//sg; | |
s/<\/?([a-z0-9:]+)[^>]*?>/(grep { lc($1) eq $_ } 'p', 'a', 'b', 'strong', 'br', 'img') ? $& : ''/iesg; #tags | |
s/(<img[^>]+class=)("[^"]*"|\S+)/my ($r,$t) = ($1,$2); $r.($t =~ m!^"! ? $t : qq!"$t"!)/iesg; | |
s/(<\/?[a-z0-9]+)\s*([^>]*)>/ $2 ? |
This file contains hidden or 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
#!/usr/bin/env perl | |
use lib 'lib'; | |
use Mojo::IOLoop; | |
use Mojo::Client; | |
my $loop = Mojo::IOLoop->new; | |
my $client = Mojo::Client->new; $client->ioloop( $loop ); | |
foo(); |
This file contains hidden or 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
# don't work | |
use Mojolicious::Lite; | |
my $loop = app->client->ioloop; | |
$loop->timer(5 => sub { | |
my $self = shift; | |
warn 1111; | |
}); |
This file contains hidden or 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
use Mojo::Client; | |
use LWP::UserAgent; | |
use Test::More tests => 6; | |
my $r; | |
$r = LWP::UserAgent->new->post( | |
'http://post.audioscrobbler.com/2.0/', | |
'Content-Type' => 'application/x-www-form-urlencoded', |
This file contains hidden or 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
use App; | |
use App::Controller; | |
my $self = App::Controller(app => App->new, tx => Mojo::Transaction::HTTP->new); | |
$self->helper(...); | |
$self->app->conf; | |
$self->app->db; |
This file contains hidden or 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
sub is_share_agent { | |
my $self = shift; | |
my $ua = $self->req->headers->user_agent; | |
my $range = $self->req->headers->header('Range'); | |
my $enc = $self->req->headers->header('Accept-Encoding'); | |
return | |
$ua =~ /facebookexternalhit/ && $range && $enc eq 'gzip' ? 'facebook' : | |
$ua eq 'Mozilla' && !$range && $enc eq 'gzip' ? 'buzz' : |
This file contains hidden or 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
#!/usr/bin/env perl | |
use common::sense; | |
use ojo; | |
die "Usage: $0 <podcast url>" unless @ARGV; | |
b(g( shift )->dom->find("enclosure[url]")->each(sub { | |
local $_ = shift->attrs->{url}; | |
say if /\.mp3$/; | |
})); |
This file contains hidden or 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
# mojo code | |
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
get '/' => sub { | |
shift->render(t => join '', 1..50_000); | |
} => 'index'; |
This file contains hidden or 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
package App:Foo; | |
use common::sense; | |
use App::User::Info; | |
use base 'App::Controller'; | |
__PACKAGE__->attr(user => sub { App::User::Info->new(%{ +shift }) }); | |
sub bar { | |
my $self = shift; |
This file contains hidden or 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
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
use App::Foo; | |
use App::Bar; | |
for (ref app) { | |
$_->attr(db => sub { ... }); | |
$_->attr(conf => sub { ... }); | |
} |