root/lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Analyze/UserAgent.pm @ 19768

Revision 19768, 1.0 kB (checked in by lopnor, 5 years ago)

lang/perl/App-Hachero: new result class, tt output plugin

  • Property svn:executable set to *
Line 
1package App::Hachero::Plugin::Analyze::UserAgent;
2use strict;
3use warnings;
4use base qw(App::Hachero::Plugin::Base);
5use DateTime::Format::MySQL;
6
7__PACKAGE__->mk_accessors(qw(result));
8
9sub analyze : Hook {
10    my ($self, $context,$args) = @_;
11    my $req = $context->currentinfo->{request} or return;
12    my $browser = $context->currentinfo->{useragent} or return;
13    my $browser_string = $browser->browser_string || '';
14    my $truncate = $self->config->{config}->{truncate_to} || 'hour';
15    my $time = $req->{datetime}->clone->truncate(to => $truncate);
16    my $key = $time->epoch.$browser_string;
17
18    $context->result->{UserAgent} ||= App::Hachero::Result::UserAgent->new;
19   
20    $context->result->{UserAgent}->push(
21        {
22            datetime => DateTime::Format::MySQL->format_datetime($time),
23            useragent => $browser_string,
24        }
25    );
26}
27
28package App::Hachero::Result::UserAgent;
29use base qw(App::Hachero::Result);
30__PACKAGE__->mk_classdata('primary' => [qw(datetime useragent)]);
31
321;
Note: See TracBrowser for help on using the browser.