Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: usage of EXPORT function

by 2teez (Priest)
on Sep 29, 2012 at 13:50 UTC ( #996381=note: print w/ replies, xml ) Need Help??


in reply to usage of EXPORT function

How the EXPORT is useful in OO programming of perl
Please note as a general rule, if the module is trying to be object oriented (OO) as stated in the OP, then export nothing.
Check the example below:

package Student; use warnings; use strict; sub new { my $type = shift; my $class = ref($type) || $type; my $self = { name => shift // "No name", score => shift // 0, }; return bless( $self, $class ); } sub name { my $self = shift; $self->{'name'} = shift // $self->{'name'}; return $self->{'name'}; } sub score { my $self = shift; $self->{'score'} = shift // $self->{'score'}; return $self->{'score'}; } 1;
Then that is called in the .pl script like so:, without the Exporting any subroutine
#!/usr/bin/perl -l use warnings; use strict; use Student; # the module used my $std = Student->new(); print join " - " => ( $std->name(), $std->score() ); # prints No name +- 0 my $std2 = Student->new( "melchi", 78 ); print join " - " => ( $std2->name(), $std2->score() ); # prints melchi + - 78 print join " - " => ( $std->name("kunle"), $std2->score(90) ); # print +s kunle - 90
You might what to check, perlobj, perlmod, perlmodlib
Hope this helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: usage of EXPORT function
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2015-07-07 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls