3 ms·
That's exactly how perl5 objects work: package Foo { sub new { my ($class, $bar) = @_; bless {bar => $bar}, $class } sub bar {
by draegtun 14y ago
That's exactly how perl5 objects work:
package Foo {
sub new {
my ($class, $bar) = @_;
bless {bar => $bar}, $class
}
sub bar {
my ($self, $x) = @_;
say $self->{bar} . $x
}
}
my $foo = Foo->new( 'Hello...' );
# method call
$foo->bar( 'baz' ); # => Hello...baz
# function call
Foo::bar( $foo, 'baz' ); # => Hello...baz