blib/lib/WWW/NameGen.pm

filter: Statementstmt 69.3% 34 / 49 Branchbran 38.8% 7 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 62.9% 51 / 81 CC 12 SCAR 26.7
CC
12
Cov
60%
generate
22.5
get_chunks
5.4
BEGIN
1.0
CRAP 14.4
↑ Summary
1 # Revision $Revision$ ( $Date$ ) - $Source$
2  
3 package WWW::NameGen;
4  
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.03';
11  
12 2 my $max = 2_500;
13 2 my $chunk_size = 250;
14 2 my @chunks;
15  
16 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 1 my ($class, %args) = @_;
18 1 my $self = bless {%args}, $class;
19 1 $self->{'ua'} = LWP::UserAgent->new;
20 1 return $self;
21 }
22  
23 1 ▶sub get_chunks {
Subroutine get_chunks: called CC=3 SCAR=16.8
Pod documented
24 1 my ($self, $count, @out) = @_;
25 1 ▶ if ($count < $chunk_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $chunk_size) { } 1 0 1
26 1 push @out, $count;
27 } else {
28 0 my $chunks = $count / $chunk_size;
29 0 my $remainder = $count % $chunk_size;
30 0 map { push @out, $chunk_size } 1 .. $chunks;
31 0 ▶ if ($remainder) { push @out, $remainder; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder) 0 0 0
32 }
33 1 return @out;
34 }
35  
36 1 ▶sub generate {
Subroutine generate: called CC=10 SCAR=31.1
Pod documented
37 1 my ($self, %args) = @_;
38  
39 1 ▶ my $min = $args{'min'} ? $args{'min'} : 10;
Branch: 1 branch
BranchTrueFalseTotal
$args{'min'} ? : 0 1 1
40 1 ▶ my $obscurity = $args{'obscurity'} ? $args{'obscurity'} : 30;
Branch: 1 branch
BranchTrueFalseTotal
$args{'obscurity'} ? : 0 1 1
41 1 ▶ my $type = $args{'type'} ? $args{'type'} : 3;
Branch: 1 branch
BranchTrueFalseTotal
$args{'type'} ? : 0 1 1
42  
43 # return cached results if we can
44 0 ▶ if (! $args{'nocache'} && $self->{'__cache'}) { return @{$self->{'__cache'}}; }
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{"nocache"} and $self->{"__cache"}) 0 1 1
Condition33%1/3
not $args{"nocache"} and $self->{"__cache"}
!ll&&!rl&&r
010
MC/DC0%0/2
not $args{"nocache"} and $self->{"__cache"}
not $args{"nocache"} $self->{"__cache"}
Truth table33%1/3
not(A) and B
A= not $args{"nocache"}B= $self->{"__cache"}
ABresult
0X0
100
111
45  
46 1 my ($count, @names) = (0, qw//);
47 1 my @chunks = $self->get_chunks($min);
48  
49 1 for my $tcount (@chunks) {
50 0 ▶ if ($count >= $max) { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($count >= $max) 0 1 1
51 my $response = $self->{ua}->post(
52 1 'http://www.kleimo.com/random/name.cfm',
53 {
54 'type' => $type,
55 'number' => $tcount,
56 'obscurity' => $obscurity,
57 'Go' => 'Generate Random Name(s)',
58 }
59 );
60  
61 1 ▶ if (! $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 1 0 1
62 1 die "Error getting data!\n";
63 }
64  
65 0 my $html = $response->content;
66 0 ▶ while ($html =~ m!target="_blank">([^<]*)</a><br>!gixm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ m[target="_blank">([^<]*)</a><br>]gimx) 0 0 0
67 0 push @names, $1;
68 }
69 0 $count += $tcount;
70 }
71  
72 0 $self->{'__cache'} = \@names;
73  
74 0 return @names;
75 }
76  
77 2 1;
78 __END__
↑ Summary