| 1 | package Faker::Plugin::HttpUserAgent; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Venus::Class 'base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | base 'Faker::Plugin'; | |
| 11 | |||
| 12 | 1 | ▶ | use POSIX 'strftime'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | # VERSION | ||
| 15 | |||
| 16 | 1 | our $VERSION = '1.19'; | |
| 17 | |||
| 18 | # METHODS | ||
| 19 | |||
| 20 | 3 | ▶ | sub execute { |
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||
| 21 | 3 | my ($self, $data) = @_; | |
| 22 | |||
| 23 | 3 | my $faker = $self->faker; | |
| 24 | 3 | my $random = $faker->random; | |
| 25 | 3 | my $class = 'Mozilla'; | |
| 26 | 3 | my $version = join '.', $random->range(5, 9), $random->range(0, 9); | |
| 27 | 3 | my $product = join '/', $class, $version; | |
| 28 | 3 | my $this_year = strftime '%Y', localtime; | |
| 29 | 3 | my $rand_year = $random->select([($this_year-20)..$this_year]); | |
| 30 | 3 | my $rand_month = sprintf('%.2d', $random->range(1, 12)); | |
| 31 | 3 | my $rand_day = sprintf('%.2d', $random->range(1, 28)); | |
| 32 | 3 | my $engine = join '/', 'Gecko', join('', $rand_year, $rand_month, $rand_day); | |
| 33 | 3 | my $platform = $random->select([ | |
| 34 | ['Macintosh', ['Mac OS ##.#', 'Max OS X ##.#'], ['Chrome', 'Safari']], | ||
| 35 | ['Windows', ['Windows ##.#', 'Windows NT ##.#'], ['Chrome', 'Edge', 'Firefox']], | ||
| 36 | ['X11', ['Linux x86', 'Linux x86_64'], ['Chrome', 'Firefox']], | ||
| 37 | ]); | ||
| 38 | 3 | my $locale = $random->select([ | |
| 39 | 'cs-CZ', | ||
| 40 | 'da-DK', | ||
| 41 | 'de-DE', | ||
| 42 | 'en-GB', | ||
| 43 | 'en-US', | ||
| 44 | 'es-ES', | ||
| 45 | 'ja-JP', | ||
| 46 | 'nb-NO', | ||
| 47 | 'pl-PL', | ||
| 48 | 'pt-BR', | ||
| 49 | 'sv-SE', | ||
| 50 | 'tr-TR', | ||
| 51 | 'zh-CN', | ||
| 52 | 'zh-TW', | ||
| 53 | ]); | ||
| 54 | 3 | my $software = join ':', 'rv', $faker->software_version; | |
| 55 | 3 | my $os_name = $platform->[0]; | |
| 56 | 3 | my $os_desc = $self->process_markers( | |
| 57 | $self->process_format($random->select($platform->[1])) | ||
| 58 | ); | ||
| 59 | 3 | my $comment = sprintf('(%s)', join('; ', $os_name, 'U', $os_desc, $software)); | |
| 60 | 3 | my $client = $random->select($platform->[2]); | |
| 61 | 3 | my $client_version = $faker->software_version; | |
| 62 | 3 | my $user_agent = "$product $comment $engine $os_name $client/$client_version"; | |
| 63 | |||
| 64 | 3 | return $user_agent; | |
| 65 | } | ||
| 66 | |||
| 67 | 1 | 1; | |
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | =head1 NAME | ||
| 72 | |||
| 73 | Faker::Plugin::HttpUserAgent - HTTP User-Agent | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | =head1 ABSTRACT | ||
| 78 | |||
| 79 | HTTP User-Agent for Faker | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | =head1 VERSION | ||
| 84 | |||
| 85 | 1.19 | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | =head1 SYNOPSIS | ||
| 90 | |||
| 91 | package main; | ||
| 92 | |||
| 93 | use Faker::Plugin::HttpUserAgent; | ||
| 94 | |||
| 95 | my $plugin = Faker::Plugin::HttpUserAgent->new; | ||
| 96 | |||
| 97 | # bless(..., "Faker::Plugin::HttpUserAgent") | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | =head1 DESCRIPTION | ||
| 102 | |||
| 103 | This package provides methods for generating fake data for HTTP user-agents. | ||
| 104 | |||
| 105 | =encoding utf8 | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | =head1 INHERITS | ||
| 110 | |||
| 111 | This package inherits behaviors from: | ||
| 112 | |||
| 113 | L<Faker::Plugin> | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | =head1 METHODS | ||
| 118 | |||
| 119 | This package provides the following methods: | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | =head2 execute | ||
| 124 | |||
| 125 | execute(HashRef $data) (Str) | ||
| 126 | |||
| 127 | The execute method returns a returns a random fake HTTP user-agent. | ||
| 128 | |||
| 129 | I<Since C<1.17>> | ||
| 130 | |||
| 131 | =over 4 | ||
| 132 | |||
| 133 | =item execute example 1 | ||
| 134 | |||
| 135 | package main; | ||
| 136 | |||
| 137 | use Faker::Plugin::HttpUserAgent; | ||
| 138 | |||
| 139 | my $plugin = Faker::Plugin::HttpUserAgent->new; | ||
| 140 | |||
| 141 | # bless(..., "Faker::Plugin::HttpUserAgent") | ||
| 142 | |||
| 143 | # my $result = $plugin->execute; | ||
| 144 | |||
| 145 | # "Mozilla/6.1 (Windows; U; Windows NT 07.6; rv:0.4.5) ... Windows Firefox/4.4.3"; | ||
| 146 | |||
| 147 | # my $result = $plugin->execute; | ||
| 148 | |||
| 149 | # "Mozilla/5.8 (Macintosh; U; Mac OS 58.2; rv:0.02) ... Macintosh Safari/0.5"; | ||
| 150 | |||
| 151 | # my $result = $plugin->execute; | ||
| 152 | |||
| 153 | # "Mozilla/9.9 (Macintosh; U; Mac OS 58.9; rv:1.25) ... Macintosh Safari/0.6"; | ||
| 154 | |||
| 155 | =back | ||
| 156 | |||
| 157 | =cut | ||
| 158 | |||
| 159 | =head2 new | ||
| 160 | |||
| 161 | new(HashRef $data) (Plugin) | ||
| 162 | |||
| 163 | The new method returns a new instance of the class. | ||
| 164 | |||
| 165 | I<Since C<1.17>> | ||
| 166 | |||
| 167 | =over 4 | ||
| 168 | |||
| 169 | =item new example 1 | ||
| 170 | |||
| 171 | package main; | ||
| 172 | |||
| 173 | use Faker::Plugin::HttpUserAgent; | ||
| 174 | |||
| 175 | my $plugin = Faker::Plugin::HttpUserAgent->new; | ||
| 176 | |||
| 177 | # bless(..., "Faker::Plugin::HttpUserAgent") | ||
| 178 | |||
| 179 | =back | ||
| 180 | |||
| 181 | =cut | ||
| 182 | |||
| 183 | =head1 AUTHORS | ||
| 184 | |||
| 185 | Awncorp, C<awncorp@cpan.org> | ||
| 186 | |||
| 187 | =cut | ||
| 188 | |||
| 189 | =head1 LICENSE | ||
| 190 | |||
| 191 | Copyright (C) 2000, Al Newkirk. | ||
| 192 | |||
| 193 | This program is free software, you can redistribute it and/or modify it under | ||
| 194 | the terms of the Apache license version 2.0. | ||
| 195 | |||
| 196 | =cut | ||