Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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;


Comment on Re: Module provides both of functional interface and object-oriented one
Select or Download Code
Re^2: Module provides both of functional interface and object-oriented one
by anazawa (Beadle) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-30 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls