in reply to Module provides both of functional interface and object-oriented one
If you forget about exporting your functions, you can try this:
package Foo; # constructor sub new { my $klass = shift; # maybe take arguments from @_ my $self = bless {}, $klass; return $self; } sub bar { my $self = shift; my ($param1, $param2) = @_; if (ref $self) { # we are an object instance print "hey, I'm an object\n"; } return ($param1 == $param2); } # and how to use it package main; # procedural Foo->bar(6 * 9, 42); # OO my $f = Foo->new(); $f->bar(15 * 17, 255);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Module provides both of functional interface and object-oriented one
by anazawa (Scribe) on Feb 17, 2012 at 06:20 UTC | |
by Anonymous Monk on Feb 17, 2012 at 08:16 UTC | |
by anazawa (Scribe) on Feb 17, 2012 at 08:51 UTC | |
by Anonymous Monk on Feb 17, 2012 at 10:49 UTC | |
by Anonymous Monk on Feb 17, 2012 at 08:03 UTC | |
by anazawa (Scribe) on Feb 17, 2012 at 08:38 UTC |