| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Chicken::Ipsum; | 
| 2 | 3 |  |  | 3 |  | 1941 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 120 |  | 
| 3 | 3 |  |  | 3 |  | 18 | use warnings; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 137 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.0.2'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Chicken::Ipsum - Generate random chicken noises | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | require Chicken::Ipsum; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | my $ci = Chicken::Ipsum->new(); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | # Generate a string of text with 5 words | 
| 18 |  |  |  |  |  |  | $words = $ci->words(5); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Generate a list of 5 words | 
| 21 |  |  |  |  |  |  | @words = $ci->words(5); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | # Generate a string of text with 2 sentences | 
| 24 |  |  |  |  |  |  | $sentences = $ci->sentences(2); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # Generate a list of 2 sentences | 
| 27 |  |  |  |  |  |  | @sentences = $ci->sentences(2); | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # Generate a string of text with 3 paragraphs | 
| 30 |  |  |  |  |  |  | $paragraphs = $ci->paragraphs(3); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # Generate a list of 3 paragraphs | 
| 33 |  |  |  |  |  |  | @paragraphs = $ci->paragraphs(3); | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | Often when developing a website or other application, it's important to have | 
| 38 |  |  |  |  |  |  | placeholders for content. This module generates prescribed amounts of clucking, | 
| 39 |  |  |  |  |  |  | cawing and other chicken-y noises. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =cut | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 3 |  |  | 3 |  | 20 | use List::Util qw/ sample /; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 406 |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 3 |  |  |  |  | 328 | use constant WORDS => [qw/ | 
| 46 |  |  |  |  |  |  | puk | 
| 47 |  |  |  |  |  |  | pukaaak | 
| 48 |  |  |  |  |  |  | cluck | 
| 49 |  |  |  |  |  |  | cluck-cluck-cluck | 
| 50 |  |  |  |  |  |  | cluckity | 
| 51 |  |  |  |  |  |  | bwak | 
| 52 |  |  |  |  |  |  | waaak | 
| 53 |  |  |  |  |  |  | bok | 
| 54 |  |  |  |  |  |  | bwok | 
| 55 |  |  |  |  |  |  | cluck-a-buh-gawk | 
| 56 |  |  |  |  |  |  | cock-a-doodle-doo | 
| 57 |  |  |  |  |  |  | bwwwaaaaaaaaaak | 
| 58 |  |  |  |  |  |  | gobble-gobble | 
| 59 |  |  |  |  |  |  | honk | 
| 60 | 3 |  |  | 3 |  | 21 | /]; | 
|  | 3 |  |  |  |  | 5 |  | 
| 61 | 3 |  |  |  |  | 174 | use constant PUNCTUATIONS => [qw/ | 
| 62 |  |  |  |  |  |  | . | 
| 63 |  |  |  |  |  |  | ... | 
| 64 |  |  |  |  |  |  | ! | 
| 65 |  |  |  |  |  |  | ? | 
| 66 | 3 |  |  | 3 |  | 19 | /]; | 
|  | 3 |  |  |  |  | 6 |  | 
| 67 | 3 |  |  | 3 |  | 17 | use constant MIN_SENTENCE_WORDS => 4; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 159 |  | 
| 68 | 3 |  |  | 3 |  | 19 | use constant MAX_SENTENCE_WORDS => 10; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 160 |  | 
| 69 | 3 |  |  | 3 |  | 18 | use constant MIN_PARAGRAPH_SENTENCES => 3; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 169 |  | 
| 70 | 3 |  |  | 3 |  | 26 | use constant MAX_PARAGRAPH_SENTENCES => 7; | 
|  | 3 |  |  |  |  | 14 |  | 
|  | 3 |  |  |  |  | 1393 |  | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head1 CONSTRUCTOR | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head2 C | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | The default constructor, C takes no arguments and returns a | 
| 77 |  |  |  |  |  |  | Chicken::Ipsum object. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =cut | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub new { | 
| 82 | 3 |  |  | 3 | 1 | 1583 | my ($class) = @_; | 
| 83 | 3 |  |  |  |  | 11 | return bless { | 
| 84 |  |  |  |  |  |  | }, $class; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head1 METHODS | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | All methods below will return a string in scalar context or list in list context. | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 C | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Returns INTEGER Chicken words. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =cut | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | sub words { | 
| 98 | 49 |  |  | 49 | 1 | 84 | my ($self, $num) = @_; | 
| 99 | 49 |  |  |  |  | 69 | my @words = sample $num, @{+WORDS}; | 
|  | 49 |  |  |  |  | 218 |  | 
| 100 | 49 | 100 |  |  |  | 220 | return wantarray ? @words : "@words"; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head2 C | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | Returns INTEGER sentences in Chicken. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =cut | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub sentences { | 
| 110 | 14 |  |  | 14 | 1 | 24 | my ($self, $num) = @_; | 
| 111 | 14 |  |  |  |  | 17 | my @sentences; | 
| 112 |  |  |  |  |  |  | # Sentences remaining "goes to" 0, LOL. | 
| 113 |  |  |  |  |  |  | # (See https://stackoverflow.com/q/1642028/237955) | 
| 114 | 14 |  |  |  |  | 33 | while ($num --> 0) { | 
| 115 | 45 |  |  |  |  | 94 | push @sentences, $self->_get_sentence(); | 
| 116 |  |  |  |  |  |  | } | 
| 117 | 14 | 100 |  |  |  | 69 | return wantarray ? @sentences : "@sentences"; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =head2 C | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | Returns INTEGER paragraphs of Chicken text. | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | =cut | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | sub paragraphs { | 
| 127 | 5 |  |  | 5 | 1 | 12 | my ($self, $num) = @_; | 
| 128 | 5 |  |  |  |  | 6 | my @paragraphs; | 
| 129 | 5 |  |  |  |  | 17 | while ($num --> 0) { | 
| 130 | 9 |  |  |  |  | 16 | push @paragraphs, $self->_get_paragraph; | 
| 131 |  |  |  |  |  |  | } | 
| 132 | 5 | 100 |  |  |  | 36 | return wantarray ? @paragraphs : join "\n\n", @paragraphs; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | sub _get_paragraph { | 
| 136 | 9 |  |  | 9 |  | 10 | my $self = shift; | 
| 137 | 9 |  |  |  |  | 63 | my $num = MIN_PARAGRAPH_SENTENCES + int rand MAX_PARAGRAPH_SENTENCES - MIN_PARAGRAPH_SENTENCES; | 
| 138 | 9 |  |  |  |  | 21 | my $paragraph = $self->sentences($num); | 
| 139 | 9 |  |  |  |  | 21 | return $paragraph; | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | sub _get_punctuation { | 
| 143 | 45 |  |  | 45 |  | 56 | return sample 1, @{+PUNCTUATIONS}; | 
|  | 45 |  |  |  |  | 188 |  | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | sub _get_sentence { | 
| 147 | 45 |  |  | 45 |  | 58 | my $self = shift; | 
| 148 | 45 |  |  |  |  | 110 | my $num = MIN_SENTENCE_WORDS + int rand MAX_SENTENCE_WORDS; | 
| 149 | 45 |  |  |  |  | 77 | my $words = ucfirst $self->words($num); | 
| 150 | 45 |  |  |  |  | 73 | return $words . _get_punctuation(); | 
| 151 |  |  |  |  |  |  | } | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 AUTHOR | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | Dan Church (DCHURCH on CPAN) | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | L | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | L | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | Copyright (C) 2023 Dan Church (h3xxgmxcom). | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify it under | 
| 168 |  |  |  |  |  |  | the same terms as Perl itself. | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =head1 AVAILABILITY | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | The latest version of this library is likely to be available from CPAN as well | 
| 173 |  |  |  |  |  |  | as: | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | L | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head1 THANKS | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | Thanks to Sebastian Carlos's L | 
| 180 |  |  |  |  |  |  | (L) for the inspiration. | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | =cut | 
| 183 |  |  |  |  |  |  | 1; |