Algorithm-C3

 view release on metacpan or  search on metacpan

lib/Algorithm/C3.pm  view on Meta::CPAN


  {
      package A;

      sub supers {
          no strict 'refs';
          @{$_[0] . '::ISA'};
      }

      package C;
      our @ISA = ('A');
      package B;
      our @ISA = ('A');
      package D;
      our @ISA = ('B', 'C');
  }

  print join ", " => Algorithm::C3::merge('D', 'supers');

The purpose of C<$func_to_fetch_parent> is to provide a way
for C<merge> to extract the parents of C<$root>. This is
needed for C3 to be able to do it's work.

The C<$cache> parameter is an entirely optional performance
measure, and should not change behavior.

If supplied, it should be a hashref that merge can use as a
private cache between runs to speed things up.  Generally
speaking, if you will be calling merge many times on related
things, and the parent fetching function will return constant
results given the same arguments during all of these calls,
you can and should reuse the same shared cache hash for all
of the calls.  Example:

  sub do_some_merging {
      my %merge_cache;
      my @foo_mro = Algorithm::C3::Merge('Foo', \&get_supers, \%merge_cache);
      my @bar_mro = Algorithm::C3::Merge('Bar', \&get_supers, \%merge_cache);
      my @baz_mro = Algorithm::C3::Merge('Baz', \&get_supers, \%merge_cache);
      my @quux_mro = Algorithm::C3::Merge('Quux', \&get_supers, \%merge_cache);
      # ...
  }

=back

=head1 CODE COVERAGE

I use B<Devel::Cover> to test the code coverage of my tests, below
is the B<Devel::Cover> report on this module's test suite.

 ------------------------ ------ ------ ------ ------ ------ ------ ------
 File                       stmt   bran   cond    sub    pod   time  total
 ------------------------ ------ ------ ------ ------ ------ ------ ------
 Algorithm/C3.pm           100.0  100.0  100.0  100.0  100.0  100.0  100.0
 ------------------------ ------ ------ ------ ------ ------ ------ ------
 Total                     100.0  100.0  100.0  100.0  100.0  100.0  100.0
 ------------------------ ------ ------ ------ ------ ------ ------ ------

=head1 SEE ALSO

=head2 The original Dylan paper

=over 4

=item L<http://www.webcom.com/haahr/dylan/linearization-oopsla96.html>

=back

=head2 The prototype Perl 6 Object Model uses C3

=over 4

=item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel/>

=back

=head2 Parrot now uses C3

=over 4

=item L<http://aspn.activestate.com/ASPN/Mail/Message/perl6-internals/2746631>

=item L<http://use.perl.org/~autrijus/journal/25768>

=back

=head2 Python 2.3 MRO related links

=over 4

=item L<http://www.python.org/2.3/mro.html>

=item L<http://www.python.org/2.2.2/descrintro.html#mro>

=back

=head2 C3 for TinyCLOS

=over 4

=item L<http://www.call-with-current-continuation.org/eggs/c3.html>

=back

=head1 AUTHORS

Stevan Little, E<lt>stevan@iinteractive.comE<gt>

Brandon L. Black, E<lt>blblack@gmail.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2006 by Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut



( run in 1.327 second using v1.01-cache-2.11-cpan-d7f47b0818f )