| 1 | package CGI::Application::Muto::MethodAttributes; | ||||||||||
| 2 | |||||||||||
| 3 | # This module code has been taken almost entirely from the module | ||||||||||
| 4 | # CGI::Application::Plugin::ActionDispatch::Attributes by Jason Yates, | ||||||||||
| 5 | # <lt>jaywhy@gmail.com<gt> | ||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use attributes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | our $VERSION = '0.1'; | |||||||||
| 11 | |||||||||||
| 12 | 2 | my @attributes; | |||||||||
| 13 | my %attr_handlers; | ||||||||||
| 14 | |||||||||||
| 15 | 2 | my $init = 1; | |||||||||
| 16 | |||||||||||
| 17 | # MODIFY_CODE_ATTRIBUTES needs to be in the inheritance tree. | ||||||||||
| 18 | 2 | ▶ | push @CGI::Application::Muto::ISA, 'CGI::Application::Muto::MethodAttributes' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | unless grep /^CGI::Application::Muto::MethodAttributes$/, @CGI::Application::Muto::ISA; | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 10 | ▶ | sub MODIFY_CODE_ATTRIBUTES { | ||||||||
|
Subroutine
MODIFY_CODE_ATTRIBUTES: called CC=5 SCAR=19.6
| |||||||||||
| 23 | 10 | my($class, $code, @attrs) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 10 | foreach (@attrs) { | |||||||||
| 26 | # Parse the attribute string ex: Regex('^/foo/bar/(\d+)/'). | ||||||||||
| 27 | 10 | my($method, $params) = /^([a-z_]\w*)(?:[(](.*)[)])?$/is; | |||||||||
| 28 | 10 | ▶ | $params =~ s/(^'|'$)//g if defined $params; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | # Attribute definition. | ||||||||||
| 31 | 10 | ▶ | if($method eq 'ATTR') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 10 | $attr_handlers{$code} = $params | |||||||||
| 33 | } | ||||||||||
| 34 | # Is a custom attribute. | ||||||||||
| 35 | else { | ||||||||||
| 36 | 0 | my $handler = $class->can($method); | |||||||||
| 37 | 0 | ▶ | next unless $handler; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | push(@attributes, [ $class, $method, $code, $params ] ); | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 10 | return (); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub init { | ||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 46 | 0 | ▶ | return unless $init; # Initialize only once | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | foreach my $attr (@attributes) { | |||||||||
| 49 | 0 | my $class = $attr->[0]; | |||||||||
| 50 | 0 | my $method = $attr->[1]; | |||||||||
| 51 | |||||||||||
| 52 | # calls: class->method( code, method, params ); | ||||||||||
| 53 | 0 | $class->$method( $attr->[2], $attr->[1], $attr->[3]); | |||||||||
| 54 | } | ||||||||||
| 55 | 0 | $init = 0; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||