File Coverage

blib/lib/WWW/UserAgent/Random.pm
Criterion Covered Total %
statement 26 28 92.8
branch 2 4 50.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 0 1 0.0
total 35 41 85.3


line stmt bran cond sub pod time code
1             package WWW::UserAgent::Random;
2              
3 1     1   28146 use 5.008008;
  1         3  
  1         45  
4 1     1   6 use strict;
  1         2  
  1         38  
5 1     1   6 use warnings;
  1         7  
  1         49  
6              
7 1     1   5 use vars qw($VERSION @ISA @EXPORT $LIBRARY);
  1         2  
  1         109  
8              
9 1     1   5 use Exporter ();
  1         2  
  1         826  
10             @ISA = qw(Exporter);
11             @EXPORT = qw(rand_ua);
12              
13             $VERSION = '0.03';
14             $LIBRARY = __PACKAGE__;
15              
16             $|=1;
17              
18             sub rand_ua {
19 1   50 1 0 14 my $agent = shift || "";
20              
21 1         62 my %agents = (
22             linux => [
23             'Emacs-W3/4.0pre.46 URL/p4.0pre.46 (i686-pc-linux; X11)',
24             'Links (2.2; Linux 2.6.25-gentoo-r9 sparc64; 166x52)',
25             'Mozilla/5.0 (compatible; Konqueror/4.0; Linux) KHTML/4.0.82 (like Gecko)',
26             'Mozilla/5.0 (compatible; Konqueror/4.1; Linux 2.6.27.7-134.fc10.x86_64; X11; x86_64) KHTML/4.1.3 (like Gecko) Fedora/4.1.3-4.fc10',
27             'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.16) Gecko/20080716 (Gentoo) Galeon/2.0.6',
28             'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060627 Galeon/2.0.1',
29             'Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.8.1.13) Gecko/20080313 Iceape/1.1.9 (Debian-1.1.9-5)',
30             'Mozilla/5.0 (X11; U; Linux sparc64; en-GB; rv:1.8.1.11) Gecko/20071217 Galeon/2.0.3 Firefox/2.0.0.11',
31             'Mozilla/5.0 (X11; U; Linux sparc64; en-GB; rv:1.8.1.11) Gecko/20071217 Galeon/2.0.3 Firefox/2.0.0.11',
32             'Mozilla/5.0 (X11; U; Linux x86_64; en; rv:1.9.0.1) Gecko/20080528 Epiphany/2.22 Firefox/3.0',
33             'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.5) Gecko/2008122903 Gentoo Iceweasel/3.0.5',
34             'Opera/5.0 (Linux 2.0.38 i386; U) [en]',
35             'Opera/6.x (Linux 2.4.8-26mdk i686; U) [it]',
36             'Seamonkey-1.1.13-1(X11; U; GNU Fedora fc 10) Gecko/20081112',
37             ],
38             macintosh => [
39             'iCab/4.0 (Macintosh; U; Intel Mac OS X)',
40             'Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)',
41             'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-gb) AppleWebKit/528.10+ (KHTML, like Gecko) Version/4.0dp1 Safari/526.11.2',
42             'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; fr-fr) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1',
43             'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Gecko/2008070206',
44             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b) Gecko/20050217',
45             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-GB; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5',
46             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031026 Firebird/0.7',
47             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3a) Gecko/20030101 Phoenix/0.5',
48             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ja-jp) AppleWebKit/419 (KHTML, like Gecko) Shiira/1.2.3 Safari/125',
49             'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4pre) Gecko/20070511 Camino/1.6pre',
50             'Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.9a8) Gecko/2007100620 GranParadiso/3.1',
51             'Opera/9.61 (Macintosh; Intel Mac OS X; U; de) Presto/2.1.1',
52             ],
53             windows => [
54             'Mozilla/3.0 (compatible; Opera/3.0; Windows 3.1) v3.1',
55             'Mozilla/3.0 (compatible; Opera/3.0; Windows 95/NT4) 3.2',
56             'Mozilla/4.0 (compatible; Lotus-Notes/5.0; Windows-NT)',
57             'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 3.0.04506; Media Center PC 5.0; SLCC1; Tablet PC 2.0)',
58             'Mozilla/4.0 (compatible; MSIE 6.0; U; Windows;) Lobo/0.98.2',
59             'Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)',
60             'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)',
61             'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Sleipnir/2.8.3',
62             'Mozilla/5.0 (compatible; Konqueror/4.0; Windows) KHTML/4.0.83 (like Gecko)',
63             'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.5) Gecko/20031007 Firebird/0.7',
64             'Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5',
65             'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko',
66             'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.8pre) Gecko/20070928 Firefox/2.0.0.7 Navigator/9.0RC1',
67             'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0a3pre',
68             'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a7) Gecko/2007080210 GranParadiso/3.0a7',
69             'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/528.10 (KHTML, like Gecko) Chrome/2.0.157.2 Safari/528.10',
70             'Opera/9.63 (Windows NT 5.2; U; en) Presto/2.1.1',
71             ],
72             openbsd => [
73             'Mozilla/5.0 (compatible; Konqueror/3.5; OpenBSD) KHTML/3.5.9 (like Gecko)',
74             'Mozilla/5.0 (X11; U; OpenBSD amd64; en; rv:1.8.1.6) Gecko/20070817 Epiphany/2.18 Firefox/2.0.0.6',
75             'Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.8.1.14) Gecko/20080821 Firefox/2.0.0.14',
76             ],
77             freebsd => [
78             'Mozilla/3.0 (WorldGate Gazelle 3.5.1 build 11; FreeBSD2.2.8-STABLE)',
79             'Mozilla/4.76 [en] (X11; U; FreeBSD 4.4-STABLE i386)',
80             'Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD) (KHTML, like Gecko)',
81             'Mozilla/5.0 (X11; U; FreeBSD i386; en; rv:1.8.1.12) Gecko/20080213 Epiphany/2.20 Firefox/2.0.0.12',
82             'Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6) Gecko/20040406 Galeon/1.3.15',
83             'Mozilla/5.0 (X11; U; GNU/kFreeBSD i686; en-US; rv:1.8.1.16) Gecko/20080702 Iceape/1.1.11 (Debian-1.1.11-1)',
84             ],
85             netbsd => [
86             'ELinks (0.4.3; NetBSD 3.0.2_PATCH sparc64; 141x19)',
87             'Mozilla/5.0 (compatible; Konqueror/3.5; NetBSD 4.0_RC3; X11) KHTML/3.5.7 (like Gecko)',
88             ],
89             os2 => [
90             'Links (2.1pre14; OS/2 1 i386; 80x33)',
91             'Mozilla/5.0 (OS/2; U; Warp 4.5; en-US; rv:1.8.1.3pre) Gecko/20070307 SeaMonkey/1.1.1+',
92             ],
93             beos => [
94             'Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.9a1) Gecko/20051002 Firefox/1.6a1',
95             'Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.9a1) Gecko/20060702 SeaMonkey/1.5a',
96             ],
97             sunos => [
98             'Mozilla/5.0 (compatible; Konqueror/3.5; SunOS) KHTML/3.5.0 (like Gecko)',
99             'Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7.5) Gecko/20050105 Epiphany/1.4.8',
100             ],
101             crawlers => [
102             'Bimbot/1.0',
103             'btbot/0.4 (+http://www.btbot.com/btbot.html)',
104             'DiamondBot',
105             'Gigabot/3.0 (http://www.gigablast.com/spider.html)',
106             'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
107             'Googlebot-Image/1.0',
108             'htdig/3.1.6 (unconfigured@htdig.searchengine.maintainer)',
109             'libwww-perl/5.808',
110             'lwp-trivial/1.41',
111             'Mnogosearch-3.1.21',
112             'Mozilla/4.0 compatible ZyBorg/1.0 DLC (wn.zyborg@looksmart.net; http://www.WISEnutbot.com)',
113             'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
114             'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
115             'msnbot/1.1 (+http://search.msn.com/msnbot.htm)',
116             'psbot/0.1 (+http://www.picsearch.com/bot.html)',
117             'PycURL/7.13.2',
118             'Python-urllib/2.5',
119             'YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)',
120             'zspider/0.9-dev http://feedback.redkolibri.com/',
121             ],
122             link_checkers => [
123             'Link Valet Online 1.1',
124             'Link Validity Check From: http://www.w3dir.com/cgi-bin (Using: Hot Links SQL by Mrcgiguy.com)',
125             'Mozilla/5.0 (compatible; LinksManager.com_bot http://linksmanager.com/linkchecker.html)',
126             'Mojoo Robot (http://www.mojoo.com/)',
127             'online link validator (http://www.dead-links.com/)',
128             'InfoWizards Reciprocal Link System PRO - (http://www.infowizards.com)',
129             'REL Link Checker Lite 1.0',
130             'SiteBar/3.3.8 (Bookmark Server; http://sitebar.org/)',
131             'Vivante Link Checker (http://www.vivante.com)',
132             'W3C-checklink/4.3 [4.42] libwww-perl/5.805',
133             'Xenu Link Sleuth 1.2i',
134             ],
135             amiga => [
136             'AmigaVoyager/3.2 (AmigaOS/MC680x0)',
137             'AmigaVoyager/2.95 (compatible; MC680x0; AmigaOS)',
138             'Mozilla/3.01 (compatible; AmigaVoyager/2.95; AmigaOS/MC680x0)',
139             'Mozilla/4.0 (compatible; AWEB 3.4 SE; AmigaOS)',
140             ],
141             others => [
142             'Dillo/0.8.6',
143             'Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.6.3',
144             'Lynx/2.8.7dev.9 libwww-FM/2.14',
145             'Links (6.9; Unix 6.9-astral sparc; 80x25)',
146             'Mozila/5.0 (iPod; U; CPU like Mac OS X; en)',
147             'Mozilla/1.10 [en] (Compatible; RISC OS 3.70; Oregano 1.10)',
148             'w3m/0.5.2',
149             ],
150             validators => [
151             'CSE HTML Validator Lite Online (http://online.htmlvalidator.com/php/onlinevallite.php)',
152             'CSSCheck/1.2.2',
153             'Cynthia 1.0',
154             'HTMLParser/1.6',
155             'P3P Validator',
156             'Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0',
157             'W3C_Validator/1.555',
158             'WDG_Validator/1.6.2',
159             ],
160             feed_readers => [
161             'Bloglines/3.1 (http://www.bloglines.com)',
162             'everyfeed-spider/2.0 (http://www.everyfeed.com)',
163             'FeedFetcher-Google; (+http://www.google.com/feedfetcher.html)',
164             'Gregarius/0.5.2 (+http://devlog.gregarius.net/docs/ua)',
165             ],
166             phones => [
167             'Alcatel-OT-600A/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 ObigoInternetBrowser/Q03C',
168             'BlackBerry7520/4.0.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/5.0.3.3 UP.Link/5.1.2.12 (Google WAP Proxy/1.0)',
169             'BlackBerry9000/4.6.0.162 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/111',
170             'Firefox (iPhone; U; CPU like Mac OS X; en)',
171             'Mobile Safari 1.1.3 (iphone; U; CPU like Mac OS X;en)',
172             'Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12; Microsoft ZuneHD 4.3)',
173             'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A535b Safari/419.3',
174             'Nokia7110/1.0 (05.01) (Google WAP Proxy/1.0)',
175             'Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21051/22.452; U; en) Presto/2.5.25 Version/10.54',
176             'Opera/9.80 (Windows Mobile; WCE; Opera Mobi/WMD-50286; U; en) Presto/2.4.13 Version/10.00',
177             'SAMSUNG-SGH-i780/1.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)',
178             'SonyEricssonZ770i/R1FA Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1',
179             ],
180             consoles => [
181             'Opera/9.00 (Nintendo Wii; U; ; 1038-58; Wii Shop Channel/1.0; en)',
182             'wii libnup/1.0',
183             'Mozilla/3.0 (compatible; Planetweb/1.125 JS SSL US Gold; Dreamcast US)',
184             'Mozilla/5.0 (PLAYSTATION 3; 2.00)',
185             'PSP (PlayStation Portable); 2.00',
186             ],
187             proxy => [
188             'BlueCoat ProxySG',
189             'Nitroglobal Anonymous Proxy',
190             'SmallProxy 3.2 Beta 20',
191             ],
192             tool => [
193             'iTunes/7.1.1 (Macintosh; N; PPC)',
194             'iTunes/7.5 (Windows; N)',
195             'Mozilla/5.0 (compatible; Google Desktop/5.9.911.3589; http://desktop.google.com/)',
196             'Mozilla/5.0 (Windows; U; it-IT) AppleWebKit/526.9+ (KHTML, like Gecko) AdobeAIR/1.5.3',
197             ],
198             shell => [
199             'curl/7.9.8 (i686-pc-linux-gnu) libcurl 7.9.8 (OpenSSL 0.9.6b) (ipv6 enabled)',
200             'Wget/1.9.1',
201             'LWP::Simple/5.835 libwww-perl/5.836',
202             'libwww-perl/5.833',
203             'Java/1.6.0_22',
204             'Python-urllib/2.7',
205             'Wget/1.9.1',
206             ],
207             cloud_platforms => [
208             'AppEngine-Google; (+http://code.google.com/appengine; appid: webetrex)',
209             'AppEngine-Google; (+http://code.google.com/appengine; appid: unblock4myspace)',
210             ],
211             wap => [
212             'Materna-WAPPreview/1.2.5.1',
213             'WapIDE-SDK/2.0; (R320s (Arial))',
214             'WinWAP 2.2 WML 1.1',
215             ],
216             );
217              
218 1 50       5 unless ($agents{$agent}){
219 1 50       5 if ($agent =~ /^browsers$/){
220 0         0 my @array = (
221             'linux','macintosh','windows','openbsd','freebsd','netbsd','sunos'
222             );
223              
224 0         0 $agent = $array[ rand @array ];
225             } else {
226 1         9 my @array = keys %agents;
227 1         55 $agent = $array[ rand @array ];
228             }
229             }
230              
231 1         2 my $rarray = scalar @{$agents{$agent}};
  1         3  
232 1         4 $rarray = int(rand($rarray));
233 1         2 my $ua = $agents{$agent}[$rarray];
234              
235 1         16 return $ua;
236             }
237              
238             1;
239             __END__