Permalink
Browse files

init

  • Loading branch information...
0 parents commit f5ae4766a0340042f5af540c1bb5c098170cfdde @miyagawa committed Jan 20, 2010
Showing with 203 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +2 −0 .shipit
  3. +4 −0 Changes
  4. +32 −0 MANIFEST
  5. +14 −0 MANIFEST.SKIP
  6. +11 −0 Makefile.PL
  7. +17 −0 README
  8. +92 −0 lib/Plack/Middleware/ConsoleLogger.pm
  9. +4 −0 t/00_compile.t
  10. +5 −0 xt/perlcritic.t
  11. +4 −0 xt/pod.t
  12. +9 −0 xt/podspell.t
  13. +4 −0 xt/synopsis.t
@@ -0,0 +1,5 @@
+META.yml
+Makefile
+inc/
+pm_to_blib
+*~
@@ -0,0 +1,2 @@
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
+git.push_to = origin
@@ -0,0 +1,4 @@
+Revision history for Perl extension Plack::Middleware::ConsoleLogger
+
+0.01 Wed Jan 20 15:15:30 2010
+ - original version
@@ -0,0 +1,32 @@
+.gitignore
+Changes
+inc/Module/Install.pm
+inc/Module/Install/AuthorTests.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/ReadmeFromPod.pm
+inc/Module/Install/Repository.pm
+inc/Module/Install/TestBase.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+inc/Spiffy.pm
+inc/Test/Base.pm
+inc/Test/Base/Filter.pm
+inc/Test/Builder.pm
+inc/Test/Builder/Module.pm
+inc/Test/More.pm
+inc/Test/Requires.pm
+lib/Plack/Middleware/ConsoleLogger.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+README
+t/00_compile.t
+xt/perlcritic.t
+xt/pod.t
+xt/podspell.t
+xt/synopsis.t
@@ -0,0 +1,14 @@
+\bRCS\b
+\bCVS\b
+\.svn/
+\.git/
+^MANIFEST\.
+^Makefile$
+~$
+\.old$
+^blib/
+^pm_to_blib
+^MakeMaker-\d
+\.gz$
+\.cvsignore
+\.shipit
@@ -0,0 +1,11 @@
+use inc::Module::Install;
+name 'Plack-Middleware-ConsoleLogger';
+all_from 'lib/Plack/Middleware/ConsoleLogger.pm';
+readme_from 'lib/Plack/Middleware/ConsoleLogger.pm';
+build_requires 'Test::More';
+use_test_base;
+test_requires 'Test::Requires';
+auto_include_deps;
+author_tests('xt');
+auto_set_repository;
+WriteAll;
17 README
@@ -0,0 +1,17 @@
+NAME
+ Plack::Middleware::ConsoleLogger -
+
+SYNOPSIS
+ use Plack::Middleware::ConsoleLogger;
+
+DESCRIPTION
+ Plack::Middleware::ConsoleLogger is
+
+AUTHOR
+ Tatsuhiko Miyagawa <miyagawa@bulknews.net>
+
+LICENSE
+ This library is free software; you can redistribute it and/or modify it
+ under the same terms as Perl itself.
+
+SEE ALSO
@@ -0,0 +1,92 @@
+package Plack::Middleware::ConsoleLogger;
+use strict;
+use parent qw(Plack::Middleware);
+use Plack::Util::Accessor qw(group);
+
+sub call {
+ my($self, $env) = @_;
+
+ my @logs;
+ $env->{'psgix.logger'} = sub {
+ my $args = shift;
+ push @logs, $args;
+ # TODO cascade?
+ };
+
+ $self->response_cb($self->app->($env), sub {
+ my $res = shift;
+
+ if (Plack::Util::header_get($res->[1], 'Content-Type') =~ /html/) {
+ return sub {
+ my $chunk = shift;
+ return unless defined $chunk;
+ $chunk =~ s!</body>!$self->generate_js(\@logs) . "</body>"!ei;
+ return $chunk;
+ };
+ }
+ });
+}
+
+sub generate_js {
+ my($self, $logs) = @_;
+
+ my $js = q(<script type="text/javascript">);
+ $js .= q/console.group("/ . $self->group . q/");/ if $self->group;
+
+ for my $log (@$logs) {
+ my $level = $log->{level};
+ $level = "error" if $level eq 'fatal';
+ my $message = $log->{message};
+ $message =~ s/\"/\\"/g;
+ $js .= qq/console.$level("$message");/;
+ }
+
+ $js .= "console.groupEnd();" if $self->group;
+ $js .= "</script>";
+ $js;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Plack::Middleware::ConsoleLogger - Write logs to Firebug or Webkit Inspector
+
+=head1 SYNOPSIS
+
+ enable "ConsoleLogger";
+
+=head1 DESCRIPTION
+
+This middleware captures logs from PSGI applications and plack
+middleware components and makes them available to see on JavaScript
+console for Firebug and Webkit Inspector.
+
+=head1 CONFIGURATIONS
+
+=over 4
+
+=item group
+
+Set the group to use with console log. Defaults to undef.
+
+=back
+
+=head1 AUTHOR
+
+Tatsuhiko Miyagawa
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+Rack::FirebugLogger
+
+=cut
+
+
@@ -0,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Plack::Middleware::ConsoleLogger' }
@@ -0,0 +1,5 @@
+use strict;
+use Test::More;
+eval q{ use Test::Perl::Critic };
+plan skip_all => "Test::Perl::Critic is not installed." if $@;
+all_critic_ok("lib");
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
@@ -0,0 +1,9 @@
+use Test::More;
+eval q{ use Test::Spelling };
+plan skip_all => "Test::Spelling is not installed." if $@;
+add_stopwords(<DATA>);
+set_spell_cmd("aspell -l en list");
+all_pod_files_spelling_ok('lib');
+__DATA__
+Tatsuhiko
+Miyagawa
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Synopsis";
+plan skip_all => "Test::Synopsis required" if $@;
+all_synopsis_ok();

0 comments on commit f5ae476

Please sign in to comment.