| 1 | 1 | ▶ | use attributes; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | package Drogo::Dispatcher::Attributes; | ||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||
| 9 | Drogo::Dispatcher::Attributes | ||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||
| 11 | Attributes: | ||||||||||||||||||||||||||
| 12 | Index, Page, Action, ActionMatch, ActionRegex | ||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||
| 14 | =head1 Synopsis | ||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||
| 16 | Code attributes. | ||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | =head1 Methods | ||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||
| 22 | 1 | our ( %dispatch_flags, %cached_flags ); | |||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||
| 24 | sub MODIFY_CODE_ATTRIBUTES | ||||||||||||||||||||||||||
| 25 | 7 | ▶ | { | ||||||||||||||||||||||||
|
Subroutine
MODIFY_CODE_ATTRIBUTES: called CC=11 SCAR=26.7
| |||||||||||||||||||||||||||
| 26 | 7 | my ($pack, $ref, @attr) = @_; | |||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||
| 28 | 7 | for my $attr ( @attr ) { | |||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||
| 30 | # ensure a $dispatch_flags{$pack} hashref, always | ||||||||||||||||||||||||||
| 31 | $dispatch_flags{$pack} = { } | ||||||||||||||||||||||||||
| 32 | 7 | ▶ | unless exists $dispatch_flags{$pack}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||
| 34 | 7 | ▶ | if ($attr eq 'Index') | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||
| 36 | 2 | $dispatch_flags{$pack}{$ref} = 'index'; | |||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||
| 38 | elsif ($attr eq 'Action') | ||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||
| 40 | 2 | $dispatch_flags{$pack}{$ref} = 'action'; | |||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||
| 42 | elsif ($attr eq 'ActionMatch') | ||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||
| 44 | 2 | $dispatch_flags{$pack}{$ref} = 'action_match'; | |||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||
| 46 | elsif ($attr =~ /^ActionRegex/) | ||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ($attr =~ /^ActionRegex\(['"](.*)['"]\)$/) | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||
| 50 | 1 | my $regex = $1; | |||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | 1 | eval { qr/$regex/ }; | |||||||||||||||||||||||||
| 53 | 1 | ▶ | die "Invalid ActionRegex in $pack (ref) $attr: $@\n" | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 54 | if $@; | ||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | 1 | $dispatch_flags{$pack}{$ref} = "action_regex-${regex}"; | |||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||
| 58 | else | ||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||
| 60 | 0 | die "Invalid ActionRegex in $pack (ref): $attr\n"; | |||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | elsif ($attr =~ /^Path/) | ||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||
| 65 | 0 | my $desc; | |||||||||||||||||||||||||
| 66 | 0 | ▶ | $desc = $1 if $attr =~ /\(['"](.*?)['"]\)$/; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||
| 68 | 0 | $dispatch_flags{$pack}{$ref} = "path-${desc}"; | |||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||
| 72 | 7 | return (); | |||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub FETCH_CODE_ATTRIBUTES { $dispatch_flags{shift}{shift} } | ||||||||||||||||||||||||
|
Subroutine
FETCH_CODE_ATTRIBUTES: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||
| 77 | =head2 get_dispatch_flags | ||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||
| 79 | Returns all autoflags specific to a package with inheritance. | ||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||
| 83 | sub get_dispatch_flags | ||||||||||||||||||||||||||
| 84 | 13 | ▶ | { | ||||||||||||||||||||||||
|
Subroutine
get_dispatch_flags: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||
| 85 | 13 | my $self = shift; | |||||||||||||||||||||||||
| 86 | 13 | ▶ | my $class = ref $self ? ref $self : $self; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||
| 88 | $cached_flags{$class} = $class->get_package_dispatch_flags | ||||||||||||||||||||||||||
| 89 | 13 | ▶ | unless exists $cached_flags{$class}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||
| 91 | 13 | return $cached_flags{$class}; | |||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||
| 94 | =head2 get_package_dispatch_flags | ||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||
| 96 | Get autoflags, only specific to the called package. | ||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||
| 100 | sub get_package_dispatch_flags | ||||||||||||||||||||||||||
| 101 | 2 | ▶ | { | ||||||||||||||||||||||||
|
Subroutine
get_package_dispatch_flags: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||
| 102 | 2 | my $self = shift; | |||||||||||||||||||||||||
| 103 | 2 | ▶ | my $class = ref $self ? ref $self : $self; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 104 | 2 | my @code_refs = keys %{$dispatch_flags{$class}}; | |||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||
| 106 | 2 | my %flag_methods; | |||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||
| 108 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 109 | 2 | for my $key (keys %{"${class}::"}) | |||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||
| 111 | 27 | my $code_ref = "${class}::${key}"; | |||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||
| 113 | 27 | ▶ | if (defined &$code_ref) | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||
| 115 | 10 | my $code = \&$code_ref; | |||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||
| 117 | $flag_methods{"$key"} = $dispatch_flags{"$class"}{"$code"} | ||||||||||||||||||||||||||
| 118 | 10 | ▶ | if grep { "$code" eq "$_" } @code_refs; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||
| 123 | 2 | return \%flag_methods; | |||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||
| 126 | =head1 AUTHORS | ||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||
| 128 | Bizowie <http://bizowie.com> | ||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||
| 130 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||
| 132 | Copyright (C) 2013 Bizowie | ||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||
| 134 | This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||
| 138 | 1 | 1; | |||||||||||||||||||||||||