The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Maker::Field::Number - A Data::Maker field class used for generating numeric data.

SYNOPSIS

  use Data::Maker;
  use Data::Maker::Field::Number;

  my $maker = Data::Maker->new(
    record_count => 10,
    fields => [
      {
        name => 'population',
        class => 'Data::Maker::Field::Number',
        args => {
          min => 5000,
          max => 5000000
        }
      }
    ]
  );

DESCRIPTION

Data::Maker::Field::Number supports the following Moose attributes:

  • int_digits_between (ArrayRef)

    This badly-named attribute defines a range of digit lengths that you want to integer portion of the generated number to fall between. For example, if you want a 3-6 digit number, you can set this to [3..6]

  • thousands_separator (Str)

    The string used to separate the thousands of the integer portion of the generated number. Defaults to ','

  • decimal_separator (Str)

    The string used to separate the integer portion from the decimal portion of the generated number. Defaults to '.'

  • separate_thousands (Bool)

    If set to a true value, the thousands of the integer portion of the generated number will be separated by the string defined by the thousands_separator attribute. Defaults to 0.

  • min (Num)

    The minimum number that is to be generated

  • max (Num)

    The maximum number that is to be generated

  • precision (Num)

    The maximum number of places to which the decimal portion of the number should be generated. To ensure that the precision is always the same length, set fixed_precision to a true value.

  • fixed_precision (Bool)

    This attribute causes the decimal portion of the number to always be the length defined by the precision attribute, even if it ends in zeros (which are usually removed). Defaults to 0.

  • static_decimal (Num)

    If this attribute is defined, the decimal portion of the number is always given that value. For example, if you want random prices that all end with 99 cents, you could set this attribute to .99

  • integer (Num)

    This method gets and sets the integer portion of the number.

  • decimal (Num)

    This method gets and sets the decimal portion of the number.

AUTHOR

John Ingram (john@funnycow.com)

LICENSE

Copyright 2010 by John Ingram. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.