DOKK / manpages / debian 11 / librose-db-object-perl / Rose::DB::Object::MakeMethods::BigNum.3pm.en
Rose::DB::Object::MakeMethods::BigNum(3pm) User Contributed Perl Documentation Rose::DB::Object::MakeMethods::BigNum(3pm)

Rose::DB::Object::MakeMethods::BigNum - Create object methods for arbitrary-precision numeric attributes for Rose::DB::Object-derived objects.

  package MyDBObject;
  our @ISA = qw(Rose::DB::Object);
  use Rose::DB::Object::MakeMethods::BigNum
  (
    bigint => 
    [
      count => 
      {
        with_init => 1,
        min       => 0,
      },
      # Important: specify very large integer values as strings
      tally => { default => '9223372036854775800' },
    ],
  );
  sub init_count { 12345 }
  ...
  $obj = MyDBObject->new(...);
  print $obj->count; # 12345
  print $obj->tally; # 9223372036854775800

Rose::DB::Object::MakeMethods::BigNum is a method maker that inherits from Rose::Object::MakeMethods. See the Rose::Object::MakeMethods documentation to learn about the interface. The method types provided by this module are described below.

All method types defined by this module are designed to work with objects that are subclasses of (or otherwise conform to the interface of) Rose::DB::Object. See the Rose::DB::Object documentation for more details.

Create get/set methods for big integer attributes. Values are stored internally and returned as Math::BigInt objects. When specifying very large integer values, use strings to be safe. (See an example in the synopsis above.)
A reference to an array of valid values. When setting the attribute, if the new value is not equal to one of the valid values, a fatal error will occur.
Determines the default value of the attribute.
The key inside the hash-based object to use for the storage of this attribute. Defaults to the name of the method.
The name of the method to call when initializing the value of an undefined attribute. Defaults to the method name with the prefix "init_" added. This option implies "with_init".
Choose the interface. The default is "get_set".
Get or set the maximum value this attribute is allowed to have.
Get or set the minimum value this attribute is allowed to have.
Modifies the behavior of the "get_set" and "get" interfaces. If the attribute is undefined, the method specified by the "init_method" option is called and the attribute is set to the return value of that method.
Creates a get/set method for a big integer object attribute. When called with an argument, the value of the attribute is set. The current value of the attribute is returned.
Creates an accessor method for a big integer object attribute that returns the current value of the attribute.
Creates a mutator method for a big integer object attribute. When called with an argument, the value of the attribute is set. If called with no arguments, a fatal error will occur.

Example:

    package MyDBObject;
    our @ISA = qw(Rose::DB::Object);
    use Rose::DB::Object::MakeMethods::BigNum
    (
      bigint => 
      [
        count => 
        {
          with_init => 1,
          min       => 0,
        },
        # Important: specify very large integer values as strings
        tally => { default => '9223372036854775800' },
      ],
    );
    sub init_count { 12345 }
    ...
    $obj = MyDBObject->new(...);
    print $obj->count; # 12345
    print $obj->tally; # 9223372036854775800
    $obj->count(-1); # Fatal error: minimum value is 0

John C. Siracusa (siracusa@gmail.com)

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

2020-06-21 perl v5.30.3