|
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 | |
|---|
| 1 | package App::Hachero::Plugin::Analyze::UserAgent; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base qw(App::Hachero::Plugin::Base); |
|---|
| 5 | use DateTime::Format::MySQL; |
|---|
| 6 | |
|---|
| 7 | __PACKAGE__->mk_accessors(qw(result)); |
|---|
| 8 | |
|---|
| 9 | sub 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 | |
|---|
| 28 | package App::Hachero::Result::UserAgent; |
|---|
| 29 | use base qw(App::Hachero::Result); |
|---|
| 30 | __PACKAGE__->mk_classdata('primary' => [qw(datetime useragent)]); |
|---|
| 31 | |
|---|
| 32 | 1; |
|---|