| 1 | package Venus::Role::Superable; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Venus::Role 'with'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | # METHODS | ||
| 11 | |||
| 12 | sub super { | ||
| 13 | 1 | ▶ | require mro; |
|
Subroutine
super: called CC=1 SCAR=0.0
Pod
documented
| |||
| 14 | 1 | goto \&next::method | |
| 15 | } | ||
| 16 | |||
| 17 | # EXPORTS | ||
| 18 | |||
| 19 | sub EXPORT { | ||
| 20 | 2 | ▶ | ['super'] |
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 21 | } | ||
| 22 | |||
| 23 | 1 | 1; | |
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | Venus::Role::Superable - Superable Role | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | =head1 ABSTRACT | ||
| 34 | |||
| 35 | Superable Role for Perl 5 | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | =head1 SYNOPSIS | ||
| 40 | |||
| 41 | package Example; | ||
| 42 | |||
| 43 | use Venus::Class; | ||
| 44 | |||
| 45 | with 'Venus::Role::Superable'; | ||
| 46 | |||
| 47 | package main; | ||
| 48 | |||
| 49 | my $example = Example->new; | ||
| 50 | |||
| 51 | # $example->super; | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | =head1 DESCRIPTION | ||
| 56 | |||
| 57 | This package modifies the consuming package and provides methods for | ||
| 58 | dispatching to superclasses using L<mro/next::method>. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | =head1 METHODS | ||
| 63 | |||
| 64 | This package provides the following methods: | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | =head2 super | ||
| 69 | |||
| 70 | super(any @args) (any) | ||
| 71 | |||
| 72 | The super method dispatches to superclasses uses the C3 method resolution order | ||
| 73 | to get better consistency in multiple inheritance situations. | ||
| 74 | |||
| 75 | I<Since C<3.55>> | ||
| 76 | |||
| 77 | =over 4 | ||
| 78 | |||
| 79 | =item super example 1 | ||
| 80 | |||
| 81 | package Example::A; | ||
| 82 | |||
| 83 | use Venus::Class; | ||
| 84 | |||
| 85 | sub test { | ||
| 86 | my ($self, @args) = @_; | ||
| 87 | |||
| 88 | return [$self, @args]; | ||
| 89 | } | ||
| 90 | |||
| 91 | package Example::B; | ||
| 92 | |||
| 93 | use Venus::Class; | ||
| 94 | |||
| 95 | base 'Example::A'; | ||
| 96 | |||
| 97 | with 'Venus::Role::Superable'; | ||
| 98 | |||
| 99 | sub test { | ||
| 100 | my ($self) = @_; | ||
| 101 | |||
| 102 | return $self->super(1..4); | ||
| 103 | } | ||
| 104 | |||
| 105 | package main; | ||
| 106 | |||
| 107 | my $example = Example::B->new; | ||
| 108 | |||
| 109 | my $result = $example->test; | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | =head1 AUTHORS | ||
| 116 | |||
| 117 | Awncorp, C<awncorp@cpan.org> | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | =head1 LICENSE | ||
| 122 | |||
| 123 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||
| 124 | |||
| 125 | This program is free software, you can redistribute it and/or modify it under | ||
| 126 | the terms of the Apache license version 2.0. | ||
| 127 | |||
| 128 | =cut | ||