File: Constants.pm

package info (click to toggle)
libparse-http-useragent-perl 0.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 668 kB
  • sloc: perl: 2,392; makefile: 7
file content (222 lines) | stat: -rw-r--r-- 6,965 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package Parse::HTTP::UserAgent::Constants;
$Parse::HTTP::UserAgent::Constants::VERSION = '0.43';
use strict;
use warnings;
use parent qw( Exporter );

our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);

use constant LIST_ROBOTS => qw(
    Wget
    curl
    libwww-perl
    GetRight
    Googlebot
    Baiduspider+
    msnbot
    bingbot
), 'Yahoo! Slurp';

BEGIN {
    my @fields = (
        'IS_EXTENDED',
        'IS_MAXTHON',           # Is this the dumb IE faker?
        'IS_PARSED',            # _parse() happened or not
        'IS_TRIDENT',           # Thanks to Microsoft, this now has a meaning
        'UA_DEVICE',            # the name of the mobile device
        'UA_DOTNET',            # [MSIE] List of .NET CLR versions
        'UA_EXTRAS',            # Extra stuff (Toolbars?) non parsable junk
        'UA_GENERIC',           # parsed with a generic parser.
        'UA_LANG',              # the language of the ua interface
        'UA_MOBILE',            # partially implemented
        'UA_MOZILLA',           # [Firefox] Mozilla revision
        'UA_NAME',              # The identifier of the ua
        'UA_ORIGINAL_NAME',     # original name if this is some variation
        'UA_ORIGINAL_VERSION',  # original version if this is some variation
        'UA_OS',                # Operating system
        'UA_PARSER',            # the parser name
        'UA_ROBOT',             # Is this a robot?
        'UA_STRENGTH',          # [MSIE] List of .NET CLR versions
        'UA_STRING',            # just for information
        'UA_STRING_ORIGINAL',   # just for information
        'UA_TABLET',            # partially implemented
        'UA_TOOLKIT',           # [Opera] ua toolkit
        'UA_TOUCH',             # windows only?
        'UA_UNKNOWN',           # failed to detect?
        'UA_VERSION',           # used for numerical ops. via qv()
        'UA_VERSION_RAW',       # the parsed version
        'UA_WAP',               # unimplemented
    );

    my $oid   = -1;
    my %field = map { $_ => ++$oid } @fields;
    my %const = (
        %field,
        LAST_ELEMENT           => -1,
        MAXID                  => $oid,
        NO_IMATCH              => -1, # for index()

        RE_CHAR_SLASH_WS       => qr{ [/\s]                                 }xms,
        RE_COMMA               => qr{ [,]                                   }xms,
        RE_DIGIT               => qr{ [0-9]                                 }xms,
        RE_DIGIT_DOT_DIGIT     => qr{ \d+ [.]? \d                           }xms,
        RE_DOTNET              => qr{ \A [.]NET (?: \s+ CLR \s+ )? (.+?) \z }xms,
        RE_EPIPHANY_GECKO      => qr{ \A (Epiphany) / (.+?) \z              }xmsi,
        RE_FIREFOX_NAMES       => qr{ Firefox|Iceweasel|Firebird|Phoenix    }xms,
        RE_HTTP                => qr{ http://                               }xms,
        RE_IX86                => qr{ \s i\d86                              }xms,
        RE_OBJECT_ID           => qr{ \A UA_                                }xms,
        RE_OPERA_MINI          => qr{ \A (Opera \s+ Mini) / (.+?) \z        }xms,
        RE_SC_WS               => qr{ ; \s?                                 }xms,
        RE_SC_WS_MULTI         => qr{ ; \s+?                                }xms,
        RE_SLASH               => qr{ /                                     }xms,
        RE_SPLIT_PARSE         => qr{ \s? ([()]) \s?                        }xms,
        RE_TWO_LETTER_LANG     => qr{ \A [a-z]{2} \z                        }xms,
        RE_WARN_INVALID        => qr{ \QVersion string\E .+? \Qcontains invalid data; ignoring:\E}xms,
        RE_WARN_OVERFLOW       => qr{ \QInteger overflow in version\E       }xms,
        RE_WHITESPACE          => qr{ \s+ }xms,
        RE_WINDOWS_OS          => qr{ \A Win(dows|NT|[0-9]+)?               }xmsi,

        ERROR_MAXTHON_MSIE     => 'Unable to extract MSIE from Maxthon UA-string',
        ERROR_MAXTHON_VERSION  => 'Unable to extract Maxthon version from Maxthon UA-string',

        OPERA9                 => 9,
        OPERA_FAKER_EXTRA_SIZE => 4,
        OPERA_TK_LENGTH        => 5,

        TK_NAME                => 0,
        TK_ORIGINAL_VERSION    => 1,
        TK_VERSION             => 2,
    );

    $const{INSIDE_UNIT_TEST}    = $ENV{PARSE_HTTP_USERAGENT_TEST_SUITE} ? 1 : 0;
    $const{INSIDE_VERBOSE_TEST} = $const{INSIDE_UNIT_TEST}
                                    && $ENV{HARNESS_IS_VERBOSE} ? 1 : 0;

    require constant;
    constant->import( \%const );
}

BEGIN {
    %EXPORT_TAGS = (
        object_ids => [qw(
            IS_PARSED
            IS_MAXTHON
            IS_TRIDENT
            IS_EXTENDED
            UA_STRING
            UA_STRING_ORIGINAL
            UA_UNKNOWN
            UA_GENERIC
            UA_NAME
            UA_VERSION_RAW
            UA_VERSION
            UA_OS
            UA_LANG
            UA_TOOLKIT
            UA_EXTRAS
            UA_DOTNET
            UA_MOZILLA
            UA_STRENGTH
            UA_ROBOT
            UA_WAP
            UA_MOBILE
            UA_TABLET
            UA_TOUCH
            UA_PARSER
            UA_DEVICE
            UA_ORIGINAL_NAME
            UA_ORIGINAL_VERSION
            MAXID
        )],
        re => [qw(
            RE_FIREFOX_NAMES
            RE_DOTNET
            RE_WINDOWS_OS
            RE_SLASH
            RE_SPLIT_PARSE
            RE_OPERA_MINI
            RE_EPIPHANY_GECKO
            RE_WHITESPACE
            RE_SC_WS
            RE_SC_WS_MULTI
            RE_HTTP
            RE_DIGIT
            RE_IX86
            RE_OBJECT_ID
            RE_CHAR_SLASH_WS
            RE_COMMA
            RE_TWO_LETTER_LANG
            RE_DIGIT_DOT_DIGIT
            RE_WARN_OVERFLOW
            RE_WARN_INVALID
        )],
        list => [qw(
            LIST_ROBOTS
        )],
        tk => [qw(
            TK_NAME
            TK_ORIGINAL_VERSION
            TK_VERSION
        )],
        etc => [qw(
            NO_IMATCH
            LAST_ELEMENT
            INSIDE_UNIT_TEST
            INSIDE_VERBOSE_TEST
        )],
        error => [qw(
            ERROR_MAXTHON_VERSION
            ERROR_MAXTHON_MSIE
        )],
        opera => [qw(
            OPERA9
            OPERA_TK_LENGTH
            OPERA_FAKER_EXTRA_SIZE
        )],
    );

    @EXPORT_OK        = map { @{ $_ } } values %EXPORT_TAGS;
    $EXPORT_TAGS{all} = [ @EXPORT_OK ];
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Parse::HTTP::UserAgent::Constants - Various constants

=head1 VERSION

version 0.43

=head1 DESCRIPTION

Internal module

=head1 DEPRECATION NOTICE

This module is B<DEPRECATED>. Please use L<HTTP::BrowserDetect> instead.

=head1 SEE ALSO

L<Parse::HTTP::UserAgent>.

=head1 AUTHOR

Burak Gursoy

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2009 by Burak Gursoy.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut