An Interest In:
Web News this Week
- February 29, 2024
- February 28, 2024
- February 27, 2024
- February 26, 2024
- February 25, 2024
- February 24, 2024
- February 23, 2024
September 22, 2022 10:56 pm GMT
Original Link: https://dev.to/yukikimoto/classplain-class-syntax-for-hash-based-perl-oo-4j6a
Class::Plain - Class Syntax for Hash-Based Perl OO
Class::Plain was released at 2022-09-22.
use Class::Plain;class Point { field x; field y; method new : common { my $self = $class->SUPER::new(@_); $self->{x} //= 0; $self->{y} //= 0; return $self; } method move { my ($x, $y) = @_; $self->{x} += $x; $self->{y} += $y; } method describe { print "A point at ($self->{x}, $self->{y})
"; }}my $point = Point->new(x => 5, y => 10);$point->describe;
Inheritance:
class Point3D : isa(Point) { field z; method new : common { my $self = $class->SUPER::new(@_); $self->{z} //= 0; return $self; } method move { my ($x, $y, $z) = @_; $self->SUPER::move($x, $y); $self->{z} += $z; } method describe { print "A point at ($self->{x}, $self->{y}, $self->{z})
"; }}
I'm strongly interested in Perl OO. I study Corinna and Object::Pad now.
A few weaks ago, I wondered "These class syntax can be applied to the traditional Perl hash-based OO modules. The syntax can be used with the all existing modules".
I remembered many OO modules. Net::FTP, IO::Socket::INET, IO::Socket::IP, LWP::UserAgent, HTTP::Tiny, XML::Simple, Data::Page, CGI, Digest::MD5, Digest::SHA, Mojolicious, Catalyst, DBIx::Class etc .
Original Link: https://dev.to/yukikimoto/classplain-class-syntax-for-hash-based-perl-oo-4j6a
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To