File: next.pm

package info (click to toggle)
libclass-c3-perl 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 240 kB
  • sloc: perl: 453; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 2,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package  # hide me from PAUSE
    next;

use strict;
use warnings;
no warnings 'redefine'; # for 00load.t w/ core support

use Scalar::Util 'blessed';

our $VERSION = '0.34';

our %METHOD_CACHE;

sub method {
    my $self     = $_[0];
    my $class    = blessed($self) || $self;
    my $indirect = caller() =~ /^(?:next|maybe::next)$/;
    my $level = $indirect ? 2 : 1;

    my ($method_caller, $label, @label);
    while ($method_caller = (caller($level++))[3]) {
      @label = (split '::', $method_caller);
      $label = pop @label;
      last unless
        $label eq '(eval)' ||
        $label eq '__ANON__';
    }

    my $method;

    my $caller   = join '::' => @label;

    $method = $METHOD_CACHE{"$class|$caller|$label"} ||= do {

        my @MRO = Class::C3::calculateMRO($class);

        my $current;
        while ($current = shift @MRO) {
            last if $caller eq $current;
        }

        no strict 'refs';
        my $found;
        foreach my $class (@MRO) {
            next if (defined $Class::C3::MRO{$class} &&
                     defined $Class::C3::MRO{$class}{methods}{$label});
            last if (defined ($found = *{$class . '::' . $label}{CODE}));
        }

        $found;
    };

    return $method if $indirect;

    die "No next::method '$label' found for $self" if !$method;

    goto &{$method};
}

sub can { method($_[0]) }

package  # hide me from PAUSE
    maybe::next;

use strict;
use warnings;
no warnings 'redefine'; # for 00load.t w/ core support

our $VERSION = '0.34';

sub method { (next::method($_[0]) || return)->(@_) }

1;

__END__

=pod

=head1 NAME

Class::C3::next - Pure-perl next::method and friends

=head1 DESCRIPTION

This module is used internally by L<Class::C3> when
necessary, and shouldn't be used (or required in
distribution dependencies) directly.  It
defines C<next::method>, C<next::can>, and
C<maybe::next::method> in pure perl.

=head1 AUTHOR

Stevan Little, <stevan@iinteractive.com>

Brandon L. Black, <blblack@gmail.com>

=head1 COPYRIGHT AND LICENSE

Copyright 2005, 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