File Coverage

blib/lib/Amce/CNA.pm
Criterion Covered Total %
statement 47 51 92.1
branch 6 10 60.0
condition 2 9 22.2
subroutine 11 11 100.0
pod n/a
total 66 81 81.4


line stmt bran cond sub pod time code
1 1     1   1652 use v5.20.0;
  1         3  
2 1     1   6 use warnings;
  1         1  
  1         37  
3             # ABSTRACT: a moer tolernat verison of mehtod location
4              
5             package Amce::CNA 0.068;
6              
7 1     1   5 use mro ();
  1         2  
  1         27  
8              
9             # This experiment lands in 5.24 so it is safe to use from v5.20 onward.
10             # -- rjbs, 2021-06-24
11 1     1   733 use if $] < 5.024, experimental => 'postderef';
  1         14  
  1         6  
12              
13             use Sub::Exporter -setup => {
14             exports => [
15             qw(AUTOLOAD),
16 2         1380 can => sub { \&__can },
17 1         9 ],
18             groups => [ default => [ qw(AUTOLOAD can) ] ],
19 1     1   733 };
  1         13621  
20              
21             #pod =head1 SYNOPSIS
22             #pod
23             #pod package Riddle::Tom;
24             #pod use Amce::CNA;
25             #pod
26             #pod sub tom_marvolo_riddle {
27             #pod return "That's me!";
28             #pod }
29             #pod
30             #pod And then...
31             #pod
32             #pod print Riddle::Tom->i_am_lord_voldemort;
33             #pod # => "That's me!"
34             #pod
35             #pod O NOES!
36             #pod
37             #pod =head1 DESCRIPTION
38             #pod
39             #pod This modlue makes it eaiser for dislexics to wriet workign Perl.
40             #pod
41             #pod =cut
42              
43             my %methods;
44              
45             sub _acroname {
46 8     8   14 my ($name) = @_;
47              
48 8         35 my $acroname = join q{}, grep { $_ ne '_' } sort split //, $name;
  42         98  
49             }
50              
51             sub __can {
52 3     3   1642 my ($class, $method) = @_;
53              
54 3         6 my $acroname = _acroname($method);
55              
56 3         17 my @path = mro::get_linear_isa($class)->@*;
57              
58 3         7 for my $pkg (@path) {
59 3   33     14 $methods{$pkg} ||= _populate_methods($pkg);
60 3 50       7 if (exists $methods{$pkg}{$acroname}) {
61 3         14 return $methods{$pkg}{$acroname};
62             }
63             }
64              
65 0         0 return;
66             }
67              
68             sub _populate_methods {
69 3     3   13 my ($pkg) = @_;
70              
71 3         4 my $return = {};
72              
73 3         9 my $stash = do { ## no critic (ConditionalDeclarations)
74 1     1   668 no strict 'refs'; ## no critic (NoStrict)
  1         2  
  1         187  
75 3         4 \%{"$pkg\::"};
  3         9  
76             };
77              
78 3         8 for my $name (keys %$stash) {
79 13 100       66 next if $name eq uc $name;
80 9 100       12 if (exists &{"$pkg\::$name"}) {
  9         26  
81 5         6 my $code = \&{$stash->{$name}};
  5         20  
82 5   33     13 $return->{_acroname($name)} ||= $code;
83             }
84             }
85              
86 3         10 return $return;
87             }
88              
89             my $error_msg = qq{Can\'t locate object method "%s" via package "%s" } .
90             qq{at %s line %d.\n};
91              
92 1     1   8 use vars qw($AUTOLOAD);
  1         2  
  1         207  
93             sub AUTOLOAD { ## no critic Autoload
94 2     2   838 my ($class, $method) = $AUTOLOAD =~ /^(.+)::([^:]+)$/;
95              
96 2 50       6 if (my $code = __can($class, $method)) {
97 2         5 return $code->(@_);
98             }
99              
100 0 0         Carp::croak "AUTOLOAD not called as method" unless @_ >= 1;
101              
102 0           my ($callpack, $callfile, $callline) = caller;
103             ## no critic Carp
104 0   0       die sprintf $error_msg, $method, ((ref $_[0])||$_[0]), $callfile, $callline;
105             }
106              
107             #pod =begin :postlude
108             #pod
109             #pod =head1 TANKHS
110             #pod
111             #pod Hans Deiter Peercay, for laughing at the joek and rembemering the original
112             #pod inpirsation for me.
113             #pod
114             #pod =head1 BUGS
115             #pod
116             #pod ueQit ysib.lpos
117             #pod
118             #pod =head1 ESE ASLO
119             #pod
120             #pod =over
121             #pod
122             #pod =item *
123             #pod
124             #pod L
125             #pod
126             #pod =back
127             #pod
128             #pod =head1 LINESCE
129             #pod
130             #pod This program is free weftsoar; you cna rdstrbteieiu it aond/r modfiy it ndeur
131             #pod the saem terms as rePl etsilf.
132             #pod
133             #pod =end :postlude
134             #pod
135             #pod =cut
136              
137             1;
138              
139             __END__