| 1 | package Catmandu::Fix::random; | ||
| 2 | |||
| 3 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | our $VERSION = '1.0201_02'; | |
| 6 | |||
| 7 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Catmandu::Fix::Has; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | with 'Catmandu::Fix::Base'; | |
| 12 | |||
| 13 | 1 | has path => (fix_arg => 1); | |
| 14 | 1 | has max => (fix_arg => 1); | |
| 15 | |||
| 16 | sub emit { | ||
| 17 | 5 | ▶ | my ($self, $fixer) = @_; |
|
Subroutine
emit: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 18 | 5 | my $path = $fixer->split_path($self->path); | |
| 19 | 5 | my $max = $fixer->emit_value($self->max); | |
| 20 | |||
| 21 | $fixer->emit_create_path( | ||
| 22 | $fixer->var, | ||
| 23 | $path, | ||
| 24 | sub { | ||
| 25 | 6 | ▶ | my $var = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 26 | 6 | "${var} = int(rand(${max}));"; | |
| 27 | } | ||
| 28 | 5 | ); | |
| 29 | } | ||
| 30 | |||
| 31 | 1 | 1; | |
| 32 | |||
| 33 | __END__ | ||
| 34 | |||
| 35 | =pod | ||
| 36 | |||
| 37 | =head1 NAME | ||
| 38 | |||
| 39 | Catmandu::Fix::random - create an random number in a field | ||
| 40 | |||
| 41 | =head1 SYNOPSIS | ||
| 42 | |||
| 43 | # Add a new field 'foo' with a random value between 0 and 9 | ||
| 44 | random(foo, 10) | ||
| 45 | |||
| 46 | # Add a new field 'my.random.number' with a random value 0 or 1 | ||
| 47 | random(my.random.number,2) | ||
| 48 | |||
| 49 | =head1 SEE ALSO | ||
| 50 | |||
| 51 | L<Catmandu::Fix> | ||
| 52 | |||
| 53 | =cut | ||