[Jifty-commit] r4584 - in jifty/trunk: lib/Jifty/Plugin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Nov 30 15:23:51 EST 2007


Author: sartak
Date: Fri Nov 30 15:23:47 2007
New Revision: 4584

Added:
   jifty/trunk/lib/Jifty/Plugin/Recorder.pm
Modified:
   jifty/trunk/   (props changed)

Log:
 r48436 at onn:  sartak | 2007-11-30 15:23:02 -0500
 Recorder plugin: record and playback accurate HTTP requests. So far the record part is done.


Added: jifty/trunk/lib/Jifty/Plugin/Recorder.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Recorder.pm	Fri Nov 30 15:23:47 2007
@@ -0,0 +1,90 @@
+package Jifty::Plugin::Recorder;
+use strict;
+use warnings;
+use base qw/Jifty::Plugin Class::Data::Inheritable/;
+__PACKAGE__->mk_accessors(qw/start path/);
+
+use Time::HiRes 'time';
+use YAML;
+
+our $VERSION = 0.01;
+
+=head2 init
+
+init installs the trigger needed before each HTTP request. It also establishes
+the baseline for all times.
+
+=cut
+
+sub init {
+    my $self = shift;
+    my %args = (
+        path => 'log',
+        @_,
+    );
+
+    return if $self->_pre_init;
+
+    Jifty::Handler->add_trigger(
+        before_request => sub { $self->before_request(@_) }
+    );
+
+    $self->start(time);
+    $self->path($args{path});
+}
+
+=head2 before_request
+
+
+=cut
+
+sub before_request
+{
+    my $self    = shift;
+    my $handler = shift;
+    my $cgi     = shift;
+
+    my $delta = time - $self->start;
+    my $request = { cgi => $cgi, ENV => \%ENV, time => $delta };
+    my $yaml = YAML::Dump($request);
+
+    my $name = $self->path . '/requests-' . int($self->start) . '.log';
+    open my $handle, '>>', $name or do {
+        Jifty->log->error("Unable to open $name for appending: $!");
+        return;
+    };
+
+    print $handle $yaml;
+
+    close $handle;
+}
+
+=head1 NAME
+
+Jifty::Plugin::Recorder
+
+=head1 DESCRIPTION
+
+
+=head1 USAGE
+
+Add the following to your site_config.yml
+
+ framework:
+   Plugins:
+     - Recorder: {}
+
+=head1 SEE ALSO
+
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 Best Practical Solutions
+
+This is free software and may be modified and distributed under the same terms as Perl itself.
+
+=cut
+
+1;
+
+


More information about the Jifty-commit mailing list