<?xml version="1.0" encoding="windows-1252"?>
<node id="303983" title="Re: Re: Using a subroutine as a module" created="2003-11-02 21:09:09" updated="2005-08-11 08:35:59">
<type id="11">
note</type>
<author id="256744">
bobn</author>
<data>
<field name="doctext">
&lt;div class="pmsig"&gt;&lt;div class="pmsig-256744"&gt;
&lt;p&gt;Actually, better not to export at all:
&lt;br /&gt;
&lt;br /&gt;
in MyModule.pm:
&lt;code&gt;
package MyModule;

sub new { bless {}, shift }
sub foo { "do some foo stuff" }
1;
&lt;/code&gt;
and in the calling code:
&lt;code&gt;
use MyModule;
my $o = new MyModule;

$o-&gt;foo();
&lt;/code&gt;
$o is an object.  It can have data, but in this case, it is just a way to tell perl where to find the subroutine foo().  This means you could have several different modules, each with a routine named 'foo;, and by using the object each module returns (customarily) from the call to new(), you can tell them apart.  Whereas if you have the misfortune to use 2 modules that both export foo into your namespace, who knows what happens?

&lt;/p&gt;&lt;p&gt;

&lt;/p&gt;--Bob Niederman, http://bob-n.com&lt;/p&gt;&lt;p&gt;All code given here is UNTESTED unless otherwise stated.&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
303965</field>
<field name="parent_node">
303972</field>
</data>
</node>
