root/lang/perl/HTTP-MobileAttribute/trunk/lib/HTTP/MobileAttribute/Agent/Base.pm @ 9180

Revision 9180, 1.6 kB (checked in by tokuhirom, 5 years ago)

Class::Component::Component::AutoloadPlugin? つかってプラグインの依存関係をよしなにはからうようにした

Line 
1package HTTP::MobileAttribute::Agent::Base;
2use strict;
3use warnings;
4require Class::Component;
5use Carp;
6
7sub import {
8    my $pkg = caller(0);
9
10    no strict 'refs';
11
12    *{"$pkg\::mk_accessors"} = \&mk_accessors;
13    *{"$pkg\::no_match"}     = \&_no_match;
14    *{"$pkg\::user_agent"}   = sub { $_[0]->request->get('User-Agent') };
15    *{"$pkg\::class_component_load_plugin_resolver"} = sub { "HTTP::MobileAttribute::Plugin::$_[1]" };
16    $pkg->mk_accessors(qw/request carrier_longname/);
17
18    unless ($pkg->isa('Class::Component')) {
19        unshift @{"$pkg\::ISA"}, 'Class::Component';
20    }
21    Class::Component::Implement->init($pkg);
22
23    $pkg->load_components(qw/DisableDynamicPlugin Autocall::InjectMethod AutoloadPlugin/);
24}
25
26sub _no_match {
27    my $self = shift;
28
29    if ($^W) {
30        carp(
31            $self->user_agent,
32            ": no match. Might be new variants. ",
33            "please contact the author of HTTP::MobileAgent!"
34        );
35    }
36}
37
38sub mk_accessors {
39    my ($class, @methods) = @_;
40
41    no strict 'refs';
42    for my $method (@methods) {
43        *{"${class}::${method}"} = sub { $_[0]->{$method} };
44    }
45}
46
471;
48__END__
49
50=encoding utf-8
51
52=head1 NAME
53
54HTTP::MobileAttribute::Agent::Base - Agent の Abstract ベースクラス
55
56=head1 DESCRIPTION
57
58HTTP::MobileAttribute::Agent::* の抽象基底クラスです。
59
60HTTP::MobileAttribute::Agent::* は、UserAgent を parse し、その属性をアクセサとして提供します。
61UserAgent からとれる以上の情報は提供しないところがミソです。
62
63=head1 AUTHOR
64
65Tokuhiro Matsuno
66
67=head1 SEE ALSO
68
69L<HTTP::MobileAttribute>
70
Note: See TracBrowser for help on using the browser.