August 2021 Archives

Object::Pad Yuki Kimoto's 2021-08-25 - Default internal data structure of the object

Object::Pad Yuki Kimoto's 2021-08-25(I fix this entry because default internal data structure is array reference, not hash reference).

This time is default internal data structure of the object.

Default internal data structure of the Object::Pad is array reference.

use strict;
use warnings;
use Data::Dumper;

use Object::Pad;

class Point {
has $x :param = 1;
has $y :param = 2;

method dump {
# Default data structure is array reference
warn Data::Dumper::Dumper $self;
}

/users/yuki_kimoto/2021/08/index.html

Object::Pad review Yuki Kimoto's 2021-08-23 - Constructor argument customize

In this time, I review constructor argument customize. BUILDARGS can customize contructer argument. It is good enough for me. I think existing library that receive hash references as argument will have a slight performance penalty because a BUILDARGS function call.


Point->new($x, $y)

use strict;
use warnings;

use Object::Pad;/users/yuki_kimoto/2021/08/index.html

Object::Pad review Yuki Kimoto's 2021-08-21 - Constructor default argument

I start to review Paul Evans's Object::Pad from my personal thinking.

Latest years, Perl core teams positively try to implement Object-Oriented feature to Perl core. I hope my review helps a little.

First time is constructor default arguments.

use Object::Pad;
 
class Point {
   has $x :param = 0;
   has $y :param = 0;
 
   method move {
      my ($dX, $dY) = @_;
      $x += $dX;
      $y += $dY;
   }
 
   method describe {
      print "A point at ($x, $y)\n";
   }
}
 
{
  my $point = Point->new(x => 5, y => 10);
  …

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.