Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by Anonymous Monk
on Feb 16, 2012 at 18:06 UTC ( [id://954310]=note: print w/replies, xml ) Need Help??


in reply to Module provides both of functional interface and object-oriented one

I concur, it's bad practice. The split over packages is brittle and unnecessary. Done with common modules (untested):
package Foo; use Moose; use Sub::Exporter -setup => {exports => [qw(procedure1 procedure2)]}; # OO stuff comes here has some_attribute … sub some_method { my ($self, @args) = @_; … } # procedural stuff comes here sub procedure1 { my $self = __PACKAGE__->new; # if needed my @args = @_; … } sub procedure2 { my $self = __PACKAGE__->new; # if needed my @args = @_; … } 1;
Usage from the main code:
use Foo qw(procedure1); procedure1(foo bar quux); my $f = Foo->new(some_attribute => baz); $f->some_method;

Replies are listed 'Best First'.
Re^2: Module provides both of functional interface and object-oriented one
by anazawa (Scribe) on Feb 16, 2012 at 18:25 UTC
    Thanks for your suggestion. I feel it's modern to use Moose. Actually, I want to use my module in CGI environment, and so I think it's heavy to load Moose. In addition, I'm a Perl beginner. I want to know how to implement above features in an old-fashioned way.
        Thanks for your comment. I didn't know what Mo is. I can't decide whether to use Moose because I have never used :) I have to learn, anyway.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found