File Coverage

blib/lib/MooX/Keyword/Random.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 5 5 100.0
pod n/a
total 31 32 96.8


line stmt bran cond sub pod time code
1             package MooX::Keyword::Random;
2 2     2   415186 use 5.006; use strict; use warnings;
  2     2   8  
  2     2   11  
  2         4  
  2         59  
  2         9  
  2         2  
  2         127  
3             our $VERSION = '1.00';
4 2     2   732 use Moo;
  2         6854  
  2         20  
5             use MooX::Keyword {
6             random => {
7             builder => sub {
8 3         255995 my ($moo, $name, $random) = @_;
9 3         98 $moo->has($name, is => 'rw');
10 3 100 66     31709 if (!ref $random && $random =~ m/\d+/) {
11 1         6 $random = [ 0 .. $random + 1 ];
12             }
13             $moo->around($name, sub {
14 3         8404 my ($orig, $self, @args) = @_;
15 3         7 return $random->[int(rand(scalar @{$random}))];
  3         66  
16 3         138 });
17             }
18             }
19 2     2   2165 };
  2         32869  
  2         26  
20              
21             1;
22              
23             =head1 NAME
24              
25             MooX::Keyword::Random - return a random result!
26              
27             =head1 VERSION
28              
29             Version 1.00
30              
31             =cut
32              
33             =head1 SYNOPSIS
34              
35             Quick summary of what the module does.
36              
37             Perhaps a little code snippet.
38              
39             package Random;
40              
41             use Moo;
42             use MooX::Keyword extends => '+Random';
43              
44             random number => 21;
45              
46             random character => ['a' .. 'z'];
47              
48             random item => [ 'pizza', 'burger', 'kebab', 'fruit', 'toast' ];
49              
50             1;
51              
52             ...
53              
54             my $rand = Random->new();
55              
56             my $num = $rand->number(); # a random number between 0 and 21.
57             my $char = $rand->character(); # a random character between a and z.
58             my $item = $rand->item(); # a random item in the provided list
59              
60             =head1 AUTHOR
61              
62             LNATION, C<< >>
63              
64             =head1 BUGS
65              
66             Please report any bugs or feature requests to C, or through
67             the web interface at L. I will be notified, and then you'll
68             automatically be notified of progress on your bug as I make changes.
69              
70             =head1 SUPPORT
71              
72             You can find documentation for this module with the perldoc command.
73              
74             perldoc MooX::Keyword::Random
75              
76             You can also look for information at:
77              
78             =over 2
79              
80             =item * RT: CPAN's request tracker (report bugs here)
81              
82             L
83              
84             =item * Search CPAN
85              
86             L
87              
88             =back
89              
90             =head1 ACKNOWLEDGEMENTS
91              
92             =head1 LICENSE AND COPYRIGHT
93              
94             This software is Copyright (c) 2023->2025 by LNATION.
95              
96             This is free software, licensed under:
97              
98             The Artistic License 2.0 (GPL Compatible)
99              
100             =cut
101              
102             1; # End of MooX::Keyword::Random