| 1 | package Yeb::Class; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||
| 3 | # ABSTRACT: Meta Class for all Yeb application classes | ||||||||||
| 4 | 2 | $Yeb::Class::VERSION = '0.104'; | |||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Package::Stash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | has app => ( | |||||||||
| 9 | is => 'ro', | ||||||||||
| 10 | required => 1, | ||||||||||
| 11 | ); | ||||||||||
| 12 | |||||||||||
| 13 | 2 | has class => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | has package_stash => ( | ||||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | lazy => 1, | ||||||||||
| 21 | 5 | ▶ | builder => sub { Package::Stash->new(shift->class) }, | ||||||||
|
Subroutine
_build_package_stash: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ); | |||||||||
| 23 | 182 | ▶ | sub add_function { | ||||||||
|
Subroutine
add_function: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 182 | my ( $self, $func, $coderef ) = @_; | |||||||||
| 25 | 182 | $self->package_stash->add_symbol('&'.$func,$coderef); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | has chain_links => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | lazy => 1, | ||||||||||
| 31 | 3 | ▶ | builder => sub {[]}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ); | |||||||||
| 33 | 21 | ▶ | sub chain { @{shift->chain_links} } | ||||||||
|
Subroutine
chain: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 10 | ▶ | sub add_to_chain { push @{shift->chain_links}, @_ } | ||||||||
|
Subroutine
add_to_chain: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | 1 | ▶ | sub prepend_to_chain { unshift @{shift->chain_links}, @_ } | ||||||||
|
Subroutine
prepend_to_chain: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | has yeb_class_functions => ( | ||||||||||
| 38 | is => 'ro', | ||||||||||
| 39 | lazy => 1, | ||||||||||
| 40 | 6 | ▶ | builder => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
| |||||||||||
| 41 | 6 | my ( $self ) = @_; | |||||||||
| 42 | { | ||||||||||
| 43 | 0 | ▶ | plugin => sub { $self->app->add_plugin($self->class,@_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | |||||||||||
| 45 | 8 | ▶ | r => sub { $self->add_to_chain(@_); return; }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 0 | ▶ | route => sub { $self->yeb_class_functions->{'r'}->(@_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | nop => sub (&) { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 0 | my ( $code ) = @_; | |||||||||
| 50 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | $code->(@_); | |||||||||
| 52 | 0 | return; | |||||||||
| 53 | 0 | }; | |||||||||
| 54 | }, | ||||||||||
| 55 | |||||||||||
| 56 | 2 | ▶ | pr => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 57 | 2 | my $route = shift; | |||||||||
| 58 | 2 | my $post_route; | |||||||||
| 59 | 2 | ▶ | if (ref $_[0] eq 'CODE') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | $post_route = "POST"; | |||||||||
| 61 | } else { | ||||||||||
| 62 | 1 | $post_route = "POST + ".(shift); | |||||||||
| 63 | } | ||||||||||
| 64 | 2 | my $post_func = shift; | |||||||||
| 65 | 2 | my @args = @_; | |||||||||
| 66 | 4 | ▶ | $self->add_to_chain($route, sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 2 | ▶ | return $post_route, sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 2 | shift; $post_func->(@_); return; | |||||||||
| 69 | 4 | }, @args; | |||||||||
| 70 | 2 | }); | |||||||||
| 71 | 2 | return; | |||||||||
| 72 | }, | ||||||||||
| 73 | 0 | ▶ | post_route => sub { $self->yeb_class_functions->{'pr'}->(@_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | middleware => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | 0 | my $middleware = shift; | |||||||||
| 77 | 0 | ▶ | $self->prepend_to_chain( "" => sub { $middleware } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | 6 | }, | |||||||||
| 81 | 2 | ); | |||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | sub call { | ||||||||
|
Subroutine
call: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 84 | 0 | my ( $self, $func, @args ) = @_; | |||||||||
| 85 | 0 | ▶ | return $self->yeb_class_functions->{$func}->(@_) if defined $self->yeb_class_functions->{$func}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | return $self->app->call($func,@args); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 6 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 90 | 6 | my ( $self ) = @_; | |||||||||
| 91 | |||||||||||
| 92 | 6 | for (keys %{$self->app->yeb_functions}) { | |||||||||
| 93 | 132 | $self->add_function($_,$self->app->yeb_functions->{$_}); | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 6 | for (keys %{$self->yeb_class_functions}) { | |||||||||
| 97 | 42 | $self->add_function($_,$self->yeb_class_functions->{$_}); | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 2 | 1; | |||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||