in reply to Calling module function from within a blessed module
This looks like you want do_soemthing() to act both as a method and a function.
If so, you need to check the first argument passed in. Inside that sub you would decide what to do either way.
sub do_something { my ($self, $param); $self = shift if ref $_[0] eq __PACKAGE__; # first argument is obj +ect $param = shift; # ...do something... if ($self) { # method ... } else { # function ... } return $param; }
If it is a mere function internal to the class, it is good practice to prepend the function name with a dash. That's an informal convention to mark functions private to the module or class.
If it is strictly a method, then the answers of my fellow monks apply: $self->method(@args)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling module function from within a blessed module
by haukex (Archbishop) on Jan 02, 2021 at 16:14 UTC | |
by shmem (Chancellor) on Jan 02, 2021 at 16:51 UTC | |
by Bod (Parson) on Jan 02, 2021 at 16:42 UTC | |
by kcott (Archbishop) on Jan 02, 2021 at 19:37 UTC | |
by haukex (Archbishop) on Jan 02, 2021 at 19:48 UTC | |
by kcott (Archbishop) on Jan 02, 2021 at 21:31 UTC | |
| |
by shmem (Chancellor) on Jan 02, 2021 at 19:50 UTC | |
by LanX (Saint) on Jan 03, 2021 at 23:57 UTC |