Skip to content

Instantly share code, notes, and snippets.

@ktat
ktat / gist:1000223
Created May 31, 2011 09:15
WebSocket perl client(AE)
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use AnyEvent;
use Protocol::WebSocket::Frame;
use Protocol::WebSocket::Handshake::Client;
use IO::Socket;
use constant {READ => 0, WRITE => 1};
@ktat
ktat / gist:1018320
Created June 10, 2011 06:19
Text::Xslate bug
use Text::Xslate;
my $t = Text::Xslate->new(syntax => 'TTerse');
print $t->render_string(<<__END__);
[%
#
#
#
#
#
#
@ktat
ktat / gist:1070298
Created July 7, 2011 19:13
SQL::Maker の $where/$opt の処理が別メソッドだったら
sub search {
my ($self, $table_name, $where, $opt) = @_;
my $table = $self->schema->get_table( $table_name );
if (! $table) {
Carp::croak("No such table $table_name");
}
my $sql_maker = $self->sql_builder;
my $stmt = $sql_maker->new_select(select => $opt->{columns} || $table->columns);
@ktat
ktat / gist:1287614
Created October 14, 2011 16:34
add_to_items
# 問題では、add_to_items($value, \@array); でしたので、書き換わりません。
# と、指摘いただきました。
{
my ($value, $array_ref) = (1, [1,2,3,4]);
add_to_items($value, $array_ref);
print join ",", @$array_ref;
# 2,3,4,5
}
@ktat
ktat / gist:1430656
Created December 4, 2011 16:50
Teng::Plugin::Pager::MySQLFoundRows::WithSQL
package Teng::Plugin::Pager::MySQLFoundRows::WithSQL;
use strict;
use warnings;
use utf8;
use Carp ();
use Teng::Iterator;
use Data::Page;
our @EXPORT = qw/search_by_sql_with_pager/;
@ktat
ktat / gist:1430680
Created December 4, 2011 16:59
Teng::Plugin::SearchBySQLAbstractMore
package Teng::Plugin::SearchBySQLAbstractMore;
use strict;
use warnings;
use utf8;
use Carp ();
use Teng::Iterator;
use Data::Page;
use SQL::Abstract::More;
our @EXPORT = qw/search_by_sql_abstract_more search_by_sql_abstract_more_with_pager/;
@ktat
ktat / gist:1566118
Created January 5, 2012 16:56
Benchmark of Query Builder
#!/usr/bin/perl
use strict;
use warnings;
use SQL::Maker;
use SQL::Abstract;
use SQL::Abstract::More;
use Benchmark qw/cmpthese/;
my $sql_abstract_more = new SQL::Abstract::More();
@ktat
ktat / gist:2699821
Created May 15, 2012 07:49
print IP address to error_log for psgi application
package Hoge::PSGIErrors;
use strict;
use IO::Handle;
sub new {
my $class = shift;
my $env = shift;
my %self;
$self{io} = IO::Handle->new;
@ktat
ktat / gist:2893362
Created June 8, 2012 03:24
DBIx::QueryLog add_skip_packages patch
diff --git a/lib/DBIx/QueryLog.pm b/lib/DBIx/QueryLog.pm
index 747cdd5..cf5e379 100644
--- a/lib/DBIx/QueryLog.pm
+++ b/lib/DBIx/QueryLog.pm
@@ -8,6 +8,7 @@ use DBI;
use Time::HiRes qw(gettimeofday tv_interval);
use Term::ANSIColor qw(colored);
use Data::Dumper ();
+use Module::Find ();
@ktat
ktat / gist:3046579
Created July 4, 2012 10:24
Teng alias patch
diff --git a/lib/Teng.pm b/lib/Teng.pm
index de2f878..a2b3207 100644
--- a/lib/Teng.pm
+++ b/lib/Teng.pm
@@ -33,14 +33,10 @@ sub load_plugin {
$class = ref($class) if ref($class);
- my $alias = delete $opt->{alias};
+ my $alias = delete $opt->{alias} || {};