root/HTTP-MobileAgent/trunk/lib/HTTP/MobileAgent/JPhone.pm

Revision 875 (checked in by miyagawa, 17 years ago)

version 0.09

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package HTTP::MobileAgent::JPhone;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.09;
6
7 use base qw(HTTP::MobileAgent);
8
9 __PACKAGE__->make_accessors(
10     qw(name version model packet_compliant
11        serial_number vendor vendor_version java_info)
12 );
13
14 sub is_j_phone { 1 }
15
16 sub parse {
17     my $self = shift;
18     my($main, @rest) = split / /, $self->user_agent;
19
20     if (@rest) {
21         # J-PHONE/4.0/J-SH51/SNJSHA3029293 SH/0001aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0
22         $self->{packet_compliant} = 1;
23         @{$self}{qw(name version model serial_number)} = split m!/!, $main;
24         if ($self->{serial_number}) {
25             $self->{serial_number} =~ s/^SN// or return $self->no_match;
26         }
27
28         my $vendor = shift @rest;
29         @{$self}{qw(vendor vendor_version)} = split m!/!, $vendor;
30
31         my %java_info = map split(m!/!), @rest;
32         $self->{java_info} = \%java_info;
33     }
34     else {
35         # J-PHONE/2.0/J-DN02
36         @{$self}{qw(name version model)} = split m!/!, $main;
37         $self->{vendor} = ($self->{model} =~ /J-([A-Z]+)/)[0] if $self->{model};
38     }
39 }
40
41 sub _make_display {
42     my $self = shift;
43     my($width, $height) = split /\*/, $self->get_header('x-jphone-display');
44
45     my($color, $depth);
46     if (my $c_str = $self->get_header('x-jphone-color')) {
47         ($color, $depth) = $c_str =~ /^([CG])(\d+)$/;
48     }
49
50     return HTTP::MobileAgent::Display->new(
51         width  => $width,
52         height => $height,
53         color  => $color eq 'C',
54         depth  => $depth,
55     );
56 }
57
58 1;
59 __END__
60
61 =head1 NAME
62
63 HTTP::MobileAgent::JPhone - J-Phone implementation
64
65 =head1 SYNOPSIS
66
67   use HTTP::MobileAgent;
68
69   local $ENV{HTTP_USER_AGENT} = "J-PHONE/2.0/J-DN02";
70   my $agent = HTTP::MobileAgent->new;
71
72   printf "Name: %s\n", $agent->name;            # "J-PHONE"
73   printf "Version: %s\n", $agent->version;      # 2.0
74   printf "Model: %s\n", $agent->model;          # "J-DN02"
75   print  "Packet is compliant.\n" if $agent->packet_compliant; # false
76
77   # only availabe in Java compliant
78   # e.g.) "J-PHONE/4.0/J-SH51/SNXXXXXXXXX SH/0001a Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.1.0"
79   printf "Serial: %s\n", $agent->serial_number; # XXXXXXXXXX
80   printf "Vendor: %s\n", $agent->vendor;        # 'SH'
81   printf "Vender Version: %s\n", $agent->vendor_version; # "0001a"
82
83   my $info = $self->java_info;          # hash reference
84   print map { "$_: $info->{$_}\n" } keys %$info;
85
86 =head1 DESCRIPTION
87
88 HTTP::MobileAgent::JPhone is a subclass of HTTP::MobileAgent, which
89 implements J-PHONE user agents.
90
91 =head1 METHODS
92
93 See L<HTTP::MobileAgent/"METHODS"> for common methods. Here are
94 HTTP::MobileAgent::JPhone specific methods.
95
96 =over 4
97
98 =item version
99
100   $version = $agent->version;
101
102 returns J-PHONE version number like '1.0'.
103
104 =item model
105
106   $model = $agent->model;
107
108 returns name of the model like 'J-DN02'.
109
110 =item packet_compliant
111
112   if ($agent->packet_compliant) { }
113
114 returns whether the agent is packet connection complicant or not.
115
116 =item serial_number
117
118   $serial_number = $agent->serial_number;
119
120 return terminal unique serial number. returns undef if user forbids to
121 send his/her serial number.
122
123 =item vendor
124
125   $vendor = $agent->vendor;
126
127 returns vendor code like 'SH'.
128
129 =item vendor_version
130
131   $vendor_version = $agent->vendor_version;
132
133 returns vendor version like '0001a'.  returns undef if unknown,
134
135 =item java_info
136
137   $info = $agent->java_info;
138
139 returns hash reference of Java profiles. Hash structure is something like:
140
141   'Profile'       => 'MIDP-1.0',
142   'Configuration' => 'CLDC-1.0',
143   'Ext-Profile'   => 'JSCL-1.1.0',
144
145 returns undef if unknown.
146
147 =back
148
149 =head1 TODO
150
151 =over 4
152
153 =item *
154
155 Area information support on http://www.dp.j-phone.com/jsky/position.html
156
157 =back
158
159 =head1 AUTHOR
160
161 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
162
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.
165
166 =head1 SEE ALSO
167
168 L<HTTP::MobileAgent>
169
170 http://www.dp.j-phone.com/jsky/user.html
171
172 http://www.dp.j-phone.com/jsky/position.html
173
174
175 =cut
Note: See TracBrowser for help on using the browser.