Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
There's a reseach going, for "Difference based module programming", which may be something related with Aspect Oriented Programming a bit.

First, you should read http://staff.aist.go.jp/y-ichisugi/mj/ for details of this programming paradigm.

OK?

Now here's an implementation of original.pm, MixJuice in Perl. Any suggestions welcome. Tarball can be downloaded from http://bulknews.net/lib/archives/original-0.01.tar.gz.

package original; use strict; use vars qw($VERSION); $VERSION = 0.01; my %Registered; sub import { my($class, $orig) = @_; my $pkg = caller; no strict 'refs'; *{"$pkg\::import"} = sub { return if exists $Registered{$pkg}; local $SIG{__WARN__} = sub {}; for my $method (__find_methods($pkg)) { next if $method eq 'import'; if (defined &{"$orig\::$method"}) { $Registered{$pkg}{$method} = \&{"$orig\::$method"}; } *{"$orig\::$method"} = \&{"$pkg\::$method"}; } }; *{"$pkg\::original"} = \&original; } sub __find_methods { my $class = shift; no strict 'refs'; my $globhash = "$class\::"; return grep { $globhash->{$_} and *{$globhash->{$_}}{CODE}; } keys %$globhash; } sub original { (my $meth = (caller(1))[3]) =~ s/.*:://; no strict 'refs'; goto &{"ORIGINAL::$meth"}; } package ORIGINAL; use vars qw($AUTOLOAD); sub AUTOLOAD { my $pkg = caller; (my $meth = $AUTOLOAD) =~ s/.*:://; my $orig = $Registered{$pkg}{$meth}; goto &$orig; } 1; __END__ =head1 NAME original - MixJuice in Perl =head1 SYNOPSIS package Animal; sub new { my($class, $hashref) = @_; bless {%$hashref}, $class; } package Animal::Speak; use original 'Animal'; sub speak { my $self = shift; return "My name is $self->{name}"; } package Animal::Dog; use original 'Animal'; sub bark { return 'bow wow'; } sub speak { my $self = shift; if ($self->{name} eq 'Snoopy') { return "Snoopy is $self->{name}"; } $self->ORIGINAL::speak(@_); # or $self->original(@_); } # Then, in a main script! use Animal; use Animal::Speak; my $spot = Animal->new({ name => 'Spot' }); print $spot->speak; # 'My name is Spot'; use Animal::Dog; my $snoopy = Animal->new({ name => 'Snoopy' }); print $snoopy->bark; # 'bow wow'; print $snoopy->speak; # 'Snoopy is Snoopy'; =head1 DESCRIPTION original.pm is a proof-of-concept implemetation of MixJuice, in Perl. See http://staff.aist.go.jp/y-ichisugi/mj/ for details :) =head1 AUTHOR Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO http://www.ogis-ri.co.jp/otc/hiroba/technical/MixJuice/, L<NEXT>, L<Exporter::Lite>, L<Class::Virtually::Abstract> =cut

--
Tatsuhiko Miyagawa
miyagawa@cpan.org


In reply to original.pm by miyagawa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (6)
    As of 2014-04-18 00:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (460 votes), past polls