Amon2-Plugin-Web-Woothee
view release on metacpan or search on metacpan
lib/Amon2/Plugin/Web/Woothee.pm view on Meta::CPAN
Amon2::Util::add_method(
$c => 'ua_is_pc',
sub {
my $self = shift;
my $category = $self->{woothee}->category || '';
return 1 if $category eq 'pc';
return 0;
},
);
Amon2::Util::add_method(
$c => 'ua_is_crawler',
sub {
my $self = shift;
$self->{woothee}->is_crawler;
},
);
Amon2::Util::add_method(
$c => 'ua_is_smartphone',
sub {
my $self = shift;
my $category = $self->{woothee}->category || '';
return 1 if $category eq 'smartphone';
return 0;
},
);
Amon2::Util::add_method(
$c => 'ua_is_mobilephone',
sub {
my $self = shift;
my $category = $self->{woothee}->category || '';
return 1 if $category eq 'mobilephone';
return 0;
},
);
Amon2::Util::add_method(
$c => 'ua_is_misc',
sub {
my $self = shift;
my $category = $self->{woothee}->category || '';
return 1 if $category eq 'misc';
return 0;
},
);
Amon2::Util::add_method( $c => 'woothee', sub { $_[0]->{woothee} } );
}
1;
package Amon2::Plugin::Web::Woothee::Object;
use strict;
use warnings;
use Woothee;
sub new {
my ($class, %args) = @_;
bless \%args, $class;
}
sub user_agent { $_[0]->{user_agent} }
sub name { $_[0]->_get('name') }
sub category { $_[0]->_get('category') }
sub os { $_[0]->_get('os') }
sub vendor { $_[0]->_get('vendor') }
sub version { $_[0]->_get('version') }
sub _get {
my ($self, $key) = @_;
$self->parse unless exists $self->{parse}{$key};
return $self->{parse}{$key};
}
sub parse {
my $self = shift;
if ( !$self->{parse} || !scalar(keys %{ $self->{parse} }) ) {
$self->{parse} = Woothee->parse($self->user_agent);
}
}
sub is_crawler {
my $self = shift;
unless ( exists $self->{is_crawler} ) {
$self->{is_crawler} ||= Woothee->is_crawler($self->user_agent);
}
return $self->{is_crawler};
}
1;
__END__
=head1 NAME
Amon2::Plugin::Web::Woothee - The Amon2 Plugin for detecting the User Agent by Woothee
=head1 SYNOPSIS
package MyApp::Web;
use Amon2::Web;
__PACKAGE__->load_plugin('Web::Woothee');
=head1 DESCRIPTION
Amon2::Plugin::Web::Woothee provides some methods for detecting User Agent on context.
=head1 METHODS
( run in 2.105 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )