Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by Anonymous Monk
on Feb 16, 2012 at 18:06 UTC ( #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
Node Status?
node history
Node Type: note [id://954310]
help
Chatterbox?
[shmem]: ww: black box, red flags...
[marto]: the first against the wall when the revolution comes is always the people who say 'the first against the wall when the revolution comes...'
marto ducks
[holli]: must watch
[holli]: good thing i added a question mark then
[shmem]: marto: nice paraphrase of 1st club rule
[holli]: plausible deniability ;)
[marto]: the first rule of chess club, touch piece
[ww]: but "don't touch 3rd rail?"\
LanX hails himself \o

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-11-21 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (301 votes). Check out past polls.

    Notices?