File Coverage

blib/lib/Acme/Daily/Fail.pm
Criterion Covered Total %
statement 65 65 100.0
branch 9 10 90.0
condition 3 5 60.0
subroutine 17 17 100.0
pod 1 1 100.0
total 95 98 96.9


line stmt bran cond sub pod time code
1             package Acme::Daily::Fail;
2             $Acme::Daily::Fail::VERSION = '1.24';
3             #ABSTRACT: generate random newspaper headlines
4              
5 2     2   263035 use strict;
  2         4  
  2         71  
6 2     2   12 use warnings;
  2         3  
  2         109  
7 2     2   1162 use Math::Random;
  2         8721  
  2         287  
8              
9             our @ISA = qw[Exporter];
10             our @EXPORT_OK = qw[get_headline];
11              
12 2     2   17 use constant PLURAL => 0;
  2         5  
  2         179  
13 2     2   10 use constant SINGULAR => 1;
  2         2  
  2         72  
14 2     2   8 use constant TENSE => 2;
  2         4  
  2         66  
15              
16 2     2   7 use constant WORD => 0;
  2         2  
  2         70  
17 2     2   16 use constant PERSON => 1;
  2         3  
  2         307  
18 2     2   11 use constant NUMBER => 2;
  2         3  
  2         66  
19              
20 2     2   7 use constant PRESENT => 0;
  2         3  
  2         60  
21 2     2   7 use constant PAST => 1;
  2         4  
  2         82  
22 2     2   6 use constant ACTIVE => 2;
  2         13  
  2         101  
23 2     2   7 use constant OBJECT => 3;
  2         3  
  2         2043  
24              
25             sub _getRandom {
26 40   50 40   58 my $array = shift || return;
27 40         50 return $array->[ scalar random_uniform_integer(1,0,$#{ $array }) ];
  40         70  
28             }
29              
30             # Auxiliary verbs (the first word in the sentence)
31             #function Verb(plural, singular, tense) {
32              
33             my $auxiliary_verbs = [
34             ["will", "will", "present"],
35             ["could", "could", "present"],
36             ["are", "is", "active"],
37             ["have", "has", "past"]
38             ];
39              
40             # Subjects (i.e. bad things)
41             #function Noun(word,person,number) {
42              
43             my $subjects = [
44             ["the labour party",3,1],
45             ["brussels",3,1],
46             ["the bbc",3,1],
47             ["the e.u.",3,1],
48             ["the euro",3,1],
49             ["the loony left",3,1],
50             ["the unions",3,2], # May be a bit quaint this one
51             ["channel 4",3,1],
52             ["your local council",3,1],
53             ["the french",3,2],
54             ["the germans",3,2],
55             ["the poles",3,2],
56             ["brussels bureaucrats",3,2],
57             ["muslims",3,2],
58             ["immigrants",3,2], # Except those from the UK to Spain & the Algarve of course
59             ["teachers",3,2],
60             ["the unemployed",3,2],
61             ["gypsies",3,2],
62             ["yobs",3,2],
63             ["hoodies",3,2],
64             ["feral children",3,2], # They hate children *and* paedophiles FFS, make your minds up
65             ["chavs",3,2],
66             ["the p.c. brigade",3,2],
67             ["cyclists",3,2],
68             ["asylum seekers",3,2], # Nicer way of saying 'brown people'
69             ["gays",3,2],
70             ["lesbians",3,2],
71             ["single mothers",3,2],
72             ["working mothers",3,2],
73             ["paedophiles",3,2],
74             ["teenage sex",3,1],
75             ["political correctness",3,1],
76             ["health & safety",3,1],
77             ["feminism",3,1],
78             ["the metric system",3,1], # For fuck's sake
79             ["dumbing-down",3,1],
80             ["rip-off britain",3,1],
81             ["the internet",3,1],
82             ["facebook",3,1], # I CAN'T BELIEVE THE MAIL ACTUALLY SAID FACEBOOK COULD GIVE YOU CANCER, FOR REAL
83             ["filth on television",3,1],
84             ["the human rights act",3,1],
85             ["the nanny state",3,1],
86             ["cancer",3,1], # Could cancer give you cancer?
87             ["binge drinking",3,1],
88             ["the house price crash",3,1],# Hahahaha
89             ["jihadists",3,2], # Topical
90             ["x factor",3,1], # Topical
91             ["foxes",3,2],
92             ["twitter",3,1], # Topical
93             ["the mmr jab",3,1], # Topical
94             ["judges",3,2],
95             ["covid",3,1], # fuck you, 2020
96             ['meghan markle',3,1],
97             ['woke',3,1],
98             ['wokery',3,1], # sophisticated
99             ];
100              
101             # Transitive phrases (i.e. bad thing they do)
102             #function Phrase(present, past, active, object) {
103              
104             my $transitive_phrases = [
105             ["give", "given", "giving", "cancer"],
106             ["give", "given", "giving", "cancer"], # Have it twice as they're so bloody obsessed by it
107             ["give", "given", "giving", "covid"],
108             ["infect", "infected", "infecting", "with AIDS"],
109             ["make", "made", "making", "obese"],
110             ["give", "given", "giving", "diabetes"],
111             ["make", "made", "making", "impotent"],
112             ["turn","turned","turning","gay"],
113             ["scrounge off","scrounged off","scrounging off",""],
114             ["tax", "taxed", "taxing", ""],
115             ["cheat", "cheated", "cheating", ""],
116             ["defraud", "defrauded", "defrauding", ""],
117             ["steal from","stolen from","stealing from",""],
118             ["burgle","burgled","burgling",""],
119             ["devalue","devalued","devaluing",""],
120             ["rip off","ripped off","ripping off",""],
121             ["molest","molested","molesting",""],
122             ["have sex with","had sex with","having sex with",""],
123             ["impregnate", "impregnated", "impregnating", ""],
124             ["steal the identity of","stolen the identity of","stealing the identity of",""],
125             ["destroy","destroyed","destroying",""],
126             ["kill","killed", "killing",""],
127             ["ruin","ruined","ruining",""],
128             ["hurt","hurt", "hurting",""]
129             ];
130              
131             # Objects (i.e. saintly, saintly things)
132             my $objects = [
133             "the british people",
134             "the middle class",
135             "middle britain",
136             "england",
137             "hard-working families",
138             "homeowners",
139             "pensioners",
140             "drivers",
141             "taxpayers",
142             "taxpayers' money",
143             "house prices",
144             "property prices", # Hahahahahahahaa
145             "britain's farmers",
146             "britain's fishermen",
147             "the countryside",
148             "british justice",
149             "british sovereignty",
150             "common sense and decency",
151             "the queen", # God bless 'er
152             "the king", # God bless 'im
153             "the royal family",
154             "the church",
155             "you",
156             "your mortgage",
157             "your pension",
158             "your daughters",
159             "your children",
160             "your house",
161             "your pets",
162             "the conservative party", # FAIL
163             "cliff richard", # Should this be in here?
164             "the memory of diana",
165             "Britain's swans", # This always stays
166             "Brexit",
167             ];
168              
169             # Matches an auxiliary verb with the subject
170             sub _match_verb_and_subject {
171 10     10   16 my ($subject,$verb) = @_;
172              
173 10 100 66     38 if ($subject->[NUMBER] == 1 && $subject->[PERSON] == 3) {
174 7         15 return $verb->[SINGULAR];
175             }
176             else {
177 3         8 return $verb->[PLURAL];
178             }
179             }
180              
181             # Matchs the transitive verb's tense with that of the verb
182             #function Phrase(present, past, active, object) {
183             sub _match_verb_and_tense {
184 10     10   15 my ($verb,$phrase) = @_;
185 10 100       22 if ($verb->[TENSE] eq "present") {
    100          
    50          
186 7         13 return $phrase->[PRESENT];
187             }
188             elsif ($verb->[TENSE] eq "past") {
189 2         5 return $phrase->[PAST];
190             }
191             elsif ($verb->[TENSE] eq "active") {
192 1         2 return $phrase->[ACTIVE];
193             }
194             }
195              
196             # Returns a Daily Mail Headline as a string
197             sub get_headline {
198 10     10 1 177640 my @sentence;
199              
200 10         22 my $subject = _getRandom($subjects);
201 10         152 my $phrase = _getRandom($transitive_phrases);
202 10         85 my $verb = _getRandom($auxiliary_verbs);
203 10         82 my $object = _getRandom($objects);
204              
205 10         121 $sentence[0] = _match_verb_and_subject($subject, $verb);
206 10         16 $sentence[1] = $subject->[WORD];
207 10         15 $sentence[2] = _match_verb_and_tense($verb, $phrase);
208 10         12 $sentence[3] = $object;
209 10 100       20 $sentence[4] = $phrase->[OBJECT] if $phrase->[OBJECT];
210              
211 10         12 my $s = join ' ', map { uc } @sentence;
  43         76  
212 10         17 $s .= '?';
213              
214 10         41 return $s;
215             }
216              
217             qq[BLOODY IMMIGRANTS];
218              
219             __END__