--- Peter Cline <[EMAIL PROTECTED]> wrote:
> > > my $object = Class->new( ....);
> >
> > Looks ok. Can you access the objects methods thereafter in that
> > scope?
> 
> Yes, I can access object methods anywhere in the file in which I
> created the object even though it has multiple namespaces.

I'm not sure what you mean by "multiple namespaces". Could you
elaborate?

Also, I'm prompted to ask exactly what is the code of Class::new()
What *exactly* is the object? Has it been bless()'d?
 
> >Is the subroutine imported?
> >Maybe you should say
> >   OtherfileNamespace::subroutine($object,$other_param);
> 
> This is probably at the heart of my problem.  The subroutine to which
> I want to pass the object is not part of a class.  It is simply a
> subroutine I have separated into a second file and use via a require
> statement. 

Modules I've done; require's I'm a little green on. =o)
Doesn't require pull the code into the current namespace?
Anyone?

> This file does not utilize the use pragma to import modules (correct 
> terminology)? 

Well, (people, check me on this) I believe a pragma is a module, like
strict.pm, while use is a function (c.f. perldoc -f use). 

  use myMod 'foo';

is functionally the equivalent to

  BEGIN { require myMod; myMod::import('myMod','foo'); }

The main difference is (I think) that modules use the package statement
to declare their own namespaces, and the use statement implies a call
to that namespace's import() function.

> Is this perhaps the problem?  Maybe the namespace in
> this  other file doesn't have access to the module? 

I'd have to see it.

> If so how can I give it access? 

A bless()'d object knows where to look.

> I have noticed that if my object is declared globally

That again makes me ask -- is it bless()'d?

> I can use it to access object methods in a separate file that does
not
> have an explicit use pragma.  However, I don't want to use a global
> variable and strict won't let me anyway (unless i tempoarily disable
> it?)

You can always access a global variable (or create one, for that
matter) by specifying the namespace.

  $main::x = 1; # satisfies strict that you know what you're doing

The common practice for objects is to use a hash reference as made by
{} (though I've seen objects that were actually references to constant
numbers, or closures....), and for a class object, it needs to be
bless()'d into that class. A common constructor:

 sub new { 
     my $class = ref($_[0]) || $_[0] || 'SomeDefault';
     bless {}, $class;
 }

Does your code do that?
Forgive me if I'm off track, here....


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to