Re: How to implement both object-method and module::function interface?

2000-08-15 Thread Chaim Frenkel

As much as I'm not for it, would

having

sub foo :method {}  # In objects vtbl
and
sub foo {}  # only if procedural call

being a valid construct and having perl dispatch appropriately, be
viable?

chaim

 "GB" == Graham Barr [EMAIL PROTECTED] writes:

GB However, if for method calls the object is moved out into $ME (or whatever)
GB then this could be an advantage to a dual API. For example

GB sub i_dont_care_sur_or_method {
GB   # just process @_, ignore $ME
GB }

GB sub dual_api {
GB   my $me = ref($ME) ? $ME : $default_obj; # Pkg-dual_api is same as sub-call
GB   # process
GB }

GB So I am hoping that we get the object removed from @_ into an predefined
GB lexical so the sub can more easily determine how it was called with
GB little expense.

-- 
Chaim FrenkelNonlinear Knowledge, Inc.
[EMAIL PROTECTED]   +1-718-236-0183



Re: How to implement both object-method and module::function interface?

2000-08-15 Thread Chaim Frenkel

 "GB" == Graham Barr [EMAIL PROTECTED] writes:

GB On Tue, Aug 15, 2000 at 10:14:36AM -0400, Chaim Frenkel wrote:
 As much as I'm not for it, would
 
 having
 
 sub foo :method {}   # In objects vtbl
 and
 sub foo {}   # only if procedural call
 
 being a valid construct and having perl dispatch appropriately, be
 viable?

GB What does it mean ? Can the first only ever be called as a methoed and the
GB second as a procedure ? Will we have to define both foo's ?

That was my suggestion. And the _author_ if supplying a dual mode
module would define both. Either one in terms of the other in order to
save coding. Or if there were a good reason, two seperate versions.

As I said I'm not enamoured of this suggestion. But it's a thought.

Do you think perl can dynamically create one of the styles from the
other?

chaim
-- 
Chaim FrenkelNonlinear Knowledge, Inc.
[EMAIL PROTECTED]   +1-718-236-0183



Re: How to implement both object-method and module::function interface?

2000-08-15 Thread Tim Bunce

On Mon, Aug 14, 2000 at 11:30:28AM -0500, Jonathan Scott Duff wrote:
 
 I'll just make up some alternatives for everyone to shoot at:
 
   use Foo;# like CGI.pm, morphs on demand
 
   use Foo;# procedural Foo
   use OOFoo;  # OO Foo
 
   use Foo ':procedural';  # default if ommitted. 
   use Foo ':OO';
 
   use Foo;# equivalent to Foo::procedural
   use Foo::procedural;
   use Foo::OO;
 
   use OOP;# sets some magic variable.
   use Foo;# Now OO rather than procedural

I don't think you can make much valuable progress down that road till
we know what Larry's thinking about how to support multiple installed
versions of a module and multiple implementations of the same 'interface'.

This is a related issue: multiple interfaces to the same code.

Tim [who's only passing through].



Re: How to implement both object-method and module::function interface?

2000-08-15 Thread Michael Fowler

On Tue, Aug 15, 2000 at 12:33:15PM +0100, Tim Bunce wrote:
 On Mon, Aug 14, 2000 at 11:30:28AM -0500, Jonathan Scott Duff wrote:
  use Foo;# like CGI.pm, morphs on demand
  
  use Foo;# procedural Foo
  use OOFoo;  # OO Foo
  
  use Foo ':procedural';  # default if ommitted. 
  use Foo ':OO';
  
  use Foo;# equivalent to Foo::procedural
  use Foo::procedural;
  use Foo::OO;
  
  use OOP;# sets some magic variable.
  use Foo;# Now OO rather than procedural

 
 I don't think you can make much valuable progress down that road till
 we know what Larry's thinking about how to support multiple installed
 versions of a module and multiple implementations of the same 'interface'.
 
 This is a related issue: multiple interfaces to the same code.

Which makes me think of the following.  You don't need to 'use' a seperate
module for a procedural or OO interface.  The module author could simply
provide a constructor in the procedural module that would require the OO
module in the background, and bless the object into that class.  This would
appear largely transparent to the user, right up until they tried to do
isa() or ref() tests on the object.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--