Loading ...
Sorry, an error occurred while loading the content.
 

Class::Prototyped - Fast prototype-based programming in Perl

Expand Messages
  • Ned Konz
    Toby Everett and I have come up with a Perl module that gives Perl a Self-like object model. If you re interested in using prototype-based programming but
    Message 1 of 5 , Aug 1, 2001
      Toby Everett and I have come up with a Perl module that gives Perl a
      Self-like object model. If you're interested in using prototype-based
      programming but can't get Self to work, you might consider this.

      One of the interesting things about this is that it uses Perl's built-in
      multiple inheritance and reflection support, and so allows mixing class-based
      and prototype-based idioms in a reasonably sensible (we think) manner.

      Tell us what you think. It's made Perl programming more interesting for us,
      at least!

      Currently, it's a bit of a memory hog (1.3K+ per object, ~3K for about 4
      slots). It executes methods just as fast as native Perl method lookup, though.

      When we figure out a way to do it without sacrificing too much performance,
      we're going to come up with a version that uses less memory than this for
      clones (currently each Prototyped object has its own symbol table; we can
      share these for clones and do a copy-on-write as soon as we can come up with
      a way to handle data slots efficiently with this model).

      Here's a copy of the announcement I made to the comp.lang.perl.announce
      newsgroup:

      Class::Prototyped - Fast prototype-based OO programming in Perl

      Class::Prototyped version 0.11 has been released to CPAN. It is
      available from your local CPAN mirror as (for instance):

      http://www.cpan.org/modules/by-authors/id/N/NE/NEDKONZ/Class-Prototyped-0.11.tar.gz
      or
      ftp://ftp.cpan.org/pub/CPAN/authors/id/N/NE/NEDKONZ/Class-Prototyped-0.11.tar.gz

      This package provides for efficient and simple prototype-based
      programming in Perl. You can provide different subroutines for each
      object, and also have objects inherit their behavior and state from
      another object.

      Method invocation is as fast as in regular Perl. Data inheritance and
      accessors are provided using closures. It does not use AUTOLOAD.

      If you're familiar with the Self language, this will look quite
      familiar.

      If you find yourself using objects whose behavior is wholly or partially
      determined by closures or CODE references, you should consider trying
      this package.

      If you're modifying @ISA or symbol tables on the fly, you should
      consider using this package.

      If you're using Class::SelfMethods, Class::Classless, or Class::Object,
      you should _definitely_ consider using this package.

      Automatic delegation is also provided, as is a full reflection
      interface.

      You can do the following:

      * Make objects that live in their own classes

      * Inherit from objects _or_ classes

      * Add or remove methods from objects or classes dynamically

      * Modify inheritance dynamically

      * Automatically delegate specific methods to a particular object or
      class

      * Mix-in behavior simply from classes or objects

      * Examine the capabilities and inheritance of your objects and/or
      classes using a simple, consistent interface (no more inspecting @ISA or
      symbol tables)

      * Perl code in external files can be mixed in to the behavior of a class
      or object (like the way Ruby handles mixed-in modules).

      Class::Prototyped was written by Ned Konz and Toby Everett; we welcome
      feedback on its design and usage. Toby wrote Class::SelfMethods and is
      now using Class::Prototyped instead.

      --
      Ned Konz
      currently: Stanwood, WA
      email: ned@...
      homepage: http://bike-nomad.com
    • Toby Everett
      ... Just to make a side note, one of the things we have demonstrated through this is that it is possible to add prototype-based semantics to class-based
      Message 2 of 5 , Aug 2, 2001
        > Toby Everett and I have come up with a Perl module that gives Perl a
        > Self-like object model. If you're interested in using prototype-based
        > programming but can't get Self to work, you might consider this.
        Just to make a side note, one of the things we have demonstrated through this
        is that it is possible to add prototype-based semantics to class-based
        object-oriented languages that support run-time inspection and creation of
        classes. The metaphors of Self: prototype-based, mirrors and reflection, and
        slots, both data, method, and parent, all translated very well and proved very
        effective in what is still a very Perlish system. The end-result is that I
        can write Perl code using the approaches one uses in Self, and it is a very
        liberating and exciting feeling. One overloads the + operator by adding the
        method slot '+'. Classes and objects are both first-class citizens - they are
        virtually equivalent in the eyes of C::P (the only difference is that named
        classes persist even if there are no references to them, where as objects
        experience normal destructor behavior). Perl becomes a guise for Self:).

        I see no reason why this same thing couldn't be done in other dynamic
        class-based object-oriented languages. Basically, all one has to do is write
        a reflection system that uses the Self semantics and translates those into the
        native inspection system.

        --Toby Everett
      • Ned Konz
        ... Thanks! ... The method we used was to make uniclasses for Self-like objects. This method is already used in a limited way in Squeak s eToy system to
        Message 3 of 5 , Aug 2, 2001
          On Thursday 02 August 2001 03:35 pm, you wrote:
          > One small step for Self, a giant leap for Perlkind! ;-)
          >
          > Great job, guys.

          Thanks!

          > On Thursday 02 August 2001 08:12, Toby Everett wrote:
          > > I see no reason why this same thing couldn't be done in other dynamic
          > > class-based object-oriented languages. Basically, all one has to do
          > > is write a reflection system that uses the Self semantics and
          > > translates those into the native inspection system.
          >
          > I am not sure about this. Most languages that are "loose enough" for
          > this kind of messing around are already prototype based (Lua, for
          > example). How would you do this in Smalltalk? I have no idea whether
          > Python or Ruby have the needed hooks.

          The method we used was to make "uniclasses" for Self-like objects. This
          method is already used in a limited way in Squeak's eToy system to allow user
          scripting of Morphs. However, to do this as efficiently as we did it for Perl
          in a single-inheritance language there would have to be some dependency
          mechanism that would allow slots to be copied down into children.

          This wasn't needed in Perl because of its extremely casual and lightweight
          multiple-inheritance model. This made things much easier to deal with. Each
          parent (class or object) is just another entry in the @ISA array that
          provides the extended method lookup order.

          Ruby also only provides a single-inheritance model. But it has a notification
          mechanism in place that allows detecting when methods are added, or when
          classes are subclassed, or when a module is mixed in. I suspect you could
          also hook method removal. These hooks could be used as part of the basis for
          a system that updates child slots as needed. Or you could use
          method_missing() (Ruby's equivalent of Smalltalk's doesNotUnderstand), but it
          would be slower.

          --
          Ned Konz
          currently: Stanwood, WA
          email: ned@...
          homepage: http://bike-nomad.com
        • Jecel Assumpcao Jr
          One small step for Self, a giant leap for Perlkind! ;-) Great job, guys. ... I am not sure about this. Most languages that are loose enough for this kind of
          Message 4 of 5 , Aug 2, 2001
            One small step for Self, a giant leap for Perlkind! ;-)

            Great job, guys.

            On Thursday 02 August 2001 08:12, Toby Everett wrote:
            > I see no reason why this same thing couldn't be done in other dynamic
            > class-based object-oriented languages. Basically, all one has to do
            > is write a reflection system that uses the Self semantics and
            > translates those into the native inspection system.

            I am not sure about this. Most languages that are "loose enough" for
            this kind of messing around are already prototype based (Lua, for
            example). How would you do this in Smalltalk? I have no idea whether
            Python or Ruby have the needed hooks.

            -- Jecel
          • Michael Lewis
            So we ll be able so see OO code like: ###~///~~3~#$~324#3 $#£$3$34£ # = abd*^!1/g//; thanks to perl ;) ... __________________________________________________
            Message 5 of 5 , Aug 3, 2001
              So we'll be able so see OO code like:

              ###~///~~3~#$~324#3"$#�$3$34�"# = abd*^!1/g//;

              thanks to perl ;)

              --- Jecel Assumpcao Jr <jecel@...> wrote:
              > One small step for Self, a giant leap for Perlkind!
              > ;-)
              >
              > Great job, guys.
              >
              > On Thursday 02 August 2001 08:12, Toby Everett
              > wrote:
              > > I see no reason why this same thing couldn't be
              > done in other dynamic
              > > class-based object-oriented languages. Basically,
              > all one has to do
              > > is write a reflection system that uses the Self
              > semantics and
              > > translates those into the native inspection
              > system.
              >
              > I am not sure about this. Most languages that are
              > "loose enough" for
              > this kind of messing around are already prototype
              > based (Lua, for
              > example). How would you do this in Smalltalk? I have
              > no idea whether
              > Python or Ruby have the needed hooks.
              >
              > -- Jecel
              >
              >
              >
              > Your use of Yahoo! Groups is subject to
              > http://docs.yahoo.com/info/terms/
              >
              >


              __________________________________________________
              Do You Yahoo!?
              Make international calls for as low as $.04/minute with Yahoo! Messenger
              http://phonecard.yahoo.com/
            Your message has been successfully submitted and would be delivered to recipients shortly.