Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 for details of this programming paradigm.


Now here's an implementation of, MixJuice in Perl. Any suggestions welcome. Tarball can be downloaded from

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 is a proof-of-concept implemetation of MixJuice, in Perl. See 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, L<NEXT>, L<Exporter::Lite>, L<Class::Virtually::Abstract> =cut

Tatsuhiko Miyagawa

In reply to by miyagawa

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    [Tabish]: Good Morning

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2017-12-13 07:26 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (348 votes). Check out past polls.