Subject: | Enhancement request w/ Patch |
This is not a bug. I needed to be able to take the words, sentences and paragraphs and manipulate them as an array. Rather than right the code to do that in my script, I modified Lorem.pm so that it would just DWIM. If you call $text->(word|sentence|paragraph) in a scalar context it returns a single string as usual. If you call them in an array context it returns the data in a list.
--- Lorem.pm.old 2005-11-28 15:27:19.819715000 -0700
+++ Lorem.pm 2005-11-28 15:31:08.516834000 -0700
@@ -39,12 +39,12 @@
my $num = shift;
my @words;
push @words, $self->get_word() for (1..$num);
- return join(' ', @words);
+ return wantarray ? @words : join ' ', @words;
}
sub get_sentence {
my $self = shift;
- my $words = $self->words( 4 + int( rand( 6 ) ) );
+ my $words = $self->words( 4 + int( rand( 6 ) ) ) . '.';
ucfirst( $words );
}
@@ -53,7 +53,7 @@
my $num = shift;
my @sentences;
push @sentences, $self->get_sentence for (1..$num);
- join( '. ', @sentences ) . '.';
+ return wantarray ? @sentences : join ' ', @sentences;
}
sub get_paragraph {
@@ -67,7 +67,7 @@
my $num = shift;
my @paragraphs;
push @paragraphs, $self->get_paragraph for (1..$num);
- join( "\n\n", @paragraphs );
+ return wantarray ? @paragraphs : join "\n\n", @paragraphs;
}
1;