Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Module provides both of functional interface and object-oriented one

by Anonymous Monk
on Feb 17, 2012 at 08:16 UTC ( #954435=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Module provides both of functional interface and object-oriented one
in thread Module provides both of functional interface and object-oriented one

On the other hand, there's nothing that forbids you from creating wrappers which you can export. Adding to my previous code:

@EXPORT_OK = qw/get_bar/; sub get_bar { my $var = shift; # your $blosxom::header hashref bar($var, @_); }


Comment on Re^3: Module provides both of functional interface and object-oriented one
Download Code
Re^4: Module provides both of functional interface and object-oriented one
by anazawa (Beadle) on Feb 17, 2012 at 08:51 UTC
    If a module looks as follows:
    package Foo; @EXPORT_OK = qw(get_foo); sub new { # constructer } sub get { # for OO interface } sub get_foo { # for procedural interface } 1;
    users may write as follows:
    $o = Foo->new(); $o->get($key); # of cource, $value $o->get_foo($key); # what's this?
    If users choose OO interface, they shouldn't be able to call 'get_foo' method. How can I solve this problem?

      If users choose OO interface, they shouldn't be able to call 'get_foo' method. How can I solve this problem?

      I'm not very well versed in Perl's OO, so someone please correct me if I'm wrong, but I don't think you can forbid users from calling it. The only thing you can do is throw an error on unexpected arguments.

      (There is a convention that a class's private methods' names begin with the underscore character, though.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954435]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2014-07-13 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (244 votes), past polls