File: demo_can.pl

package info (click to toggle)
libclass-std-perl 0.013-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 280 kB
  • ctags: 101
  • sloc: perl: 872; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 448 bytes parent folder | download | duplicates (4)
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
package Foo;
use Class::Std;

sub foo { print "$_[0]\->Foo::foo()\n" }


package Bar;
use Class::Std;

sub AUTOMETHOD {
    return sub { print "$_[0]\->Bar::foo()\n" } if m/\A foo \Z/xms;
    return;
}


package Baz;
use base qw( Bar );

package Qux;


package main;

if ($meth_ref = Foo->can('foo')) {
    Foo->$meth_ref();
}

if ($meth_ref = Bar->can('foo')) {
    Bar->$meth_ref();
}

if ($meth_ref = Qux->can('foo')) {
    Qux->$meth_ref();
}