line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HO::abstract |
2
|
|
|
|
|
|
|
# ********************* |
3
|
3
|
|
|
3
|
|
73666
|
; use strict; use warnings; |
|
3
|
|
|
3
|
|
14
|
|
|
3
|
|
|
|
|
81
|
|
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
115
|
|
4
|
|
|
|
|
|
|
our $VERSION='0.02'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
; use Package::Subroutine () |
7
|
3
|
|
|
3
|
|
472
|
; use Carp () |
|
3
|
|
|
|
|
3515
|
|
|
3
|
|
|
|
|
53
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
18
|
; our $METHOD_DIE = sub |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1474
|
|
10
|
|
|
|
|
|
|
{ my ($method) = @_ |
11
|
|
|
|
|
|
|
; return sub |
12
|
2
|
|
|
2
|
|
1301
|
{ my $pkg = $_[0]; |
13
|
2
|
100
|
|
|
|
7
|
; if(ref($_[0])) |
14
|
1
|
|
|
|
|
3
|
{ $pkg = ref($_[0]) |
15
|
|
|
|
|
|
|
} |
16
|
2
|
|
|
|
|
24
|
; Carp::croak("Class '$pkg' does not override ${method}()") |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
; our $CLASS_DIE = sub |
21
|
|
|
|
|
|
|
{ my ($class) = @_ |
22
|
|
|
|
|
|
|
; return sub |
23
|
5
|
|
|
5
|
|
10
|
{ my $instanceof = ref($_[0]) |
24
|
5
|
50
|
|
|
|
15
|
; if($instanceof eq $class) |
25
|
5
|
|
|
|
|
64
|
{ Carp::croak("Abstract class '$class' should not be instantiated.") |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else |
28
|
0
|
|
|
|
|
|
{ Carp::croak("Class '$instanceof' should overwrite method init from abstract class '$class'.") |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
; { our $target |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
; sub abstract_method |
36
|
1
|
|
|
1
|
1
|
3
|
{ my @methods = @_ |
37
|
1
|
50
|
|
|
|
3
|
; unless(defined($target)) |
38
|
0
|
|
|
|
|
0
|
{ Carp::croak("No target class defined!") |
39
|
|
|
|
|
|
|
} |
40
|
1
|
|
|
|
|
2
|
; foreach my $method (@methods) |
41
|
1
|
|
|
|
|
3
|
{ install Package::Subroutine:: |
42
|
|
|
|
|
|
|
$target => $method => $METHOD_DIE->($method) |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
; sub abstract_class |
47
|
3
|
100
|
|
3
|
1
|
13
|
{ my (@classes) = @_ ? @_ : ($target) |
48
|
3
|
|
|
|
|
7
|
; foreach my $class (@classes) |
49
|
5
|
|
|
|
|
26
|
{ install Package::Subroutine:: |
50
|
|
|
|
|
|
|
$class => 'init' => $CLASS_DIE->($class) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
; sub import |
55
|
6
|
|
|
6
|
|
1196
|
{ my ($self,$action,@params) = @_ |
56
|
6
|
100
|
|
|
|
26
|
; return unless defined $action |
57
|
5
|
|
|
|
|
13
|
; local $target = caller |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
; my $perform = |
60
|
|
|
|
|
|
|
{ 'method' => \&abstract_method |
61
|
|
|
|
|
|
|
, 'class' => \&abstract_class |
62
|
5
|
|
|
|
|
121
|
}->{$action} |
63
|
5
|
100
|
|
|
|
28
|
; die "Unknown action '$action' in use of HO::abstract." unless $perform |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
9
|
; $perform->(@params) |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
; 1 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |