31178249f31483edfad77e89a9b2e3331d1cfeaf
[catagits/Catalyst-Runtime.git] / lib / Catalyst / AttrContainer.pm
1 package Catalyst::AttrContainer;
2
3 use Moose;
4 #use MooseX::ClassAttribute;
5 use Catalyst::Exception;
6 use Class::Data::Inheritable;
7 {
8   my $mk_classdata =  Class::Data::Inheritable->can('mk_classdata');
9   __PACKAGE__->meta->add_method(mk_classdata => $mk_classdata);
10 }
11
12 __PACKAGE__->mk_classdata(_attr_cache   => {});
13 __PACKAGE__->mk_classdata(_action_cache => []);
14
15 # class_has _attr_cache   => (
16 #                             is => 'rw',
17 #                             isa => 'HashRef',
18 #                             required => 1,
19 #                             default => sub{{}}
20 #                            );
21 # class_has _action_cache => (
22 #                             is => 'rw',
23 #                             isa => 'ArrayRef',
24 #                             required => 1,
25 #                             default => sub{ [] }
26 #                           );
27
28 # note - see attributes(3pm)
29 sub MODIFY_CODE_ATTRIBUTES {
30     my ( $class, $code, @attrs ) = @_;
31     #can't the below just be $class->_attr_cache->{$code} = \@attrs; ?
32     $class->_attr_cache( { %{ $class->_attr_cache }, $code => [@attrs] } );
33     #why can't this just be push @{$class->_action_cache}, [$code, \@attrs] ?
34     $class->_action_cache(
35         [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] );
36     return ();
37 }
38
39 sub FETCH_CODE_ATTRIBUTES { $_[0]->_attr_cache->{ $_[1] } || () }
40
41 =head1 NAME
42
43 Catalyst::AttrContainer
44
45 =head1 SYNOPSIS
46
47 =head1 DESCRIPTION
48
49 This class sets up the code attribute cache.  It's a base class for
50 L<Catalyst::Controller>.
51
52 =head1 METHODS
53
54 =head2 FETCH_CODE_ATTRIBUTES
55
56 Attribute function. See attributes(3pm)
57
58 =head2 MODIFY_CODE_ATTRIBUTES
59
60 Attribute function. See attributes(3pm)
61
62 =head1 SEE ALSO
63
64 L<Catalyst::Dispatcher>
65 L<Catalyst>.
66
67 =head1 AUTHOR
68
69 Sebastian Riedel, C<sri@cpan.org>
70 Marcus Ramberg, C<mramberg@cpan.org>
71
72 =head1 COPYRIGHT
73
74 This program is free software, you can redistribute it and/or modify it under
75 the same terms as Perl itself.
76
77 =cut
78
79 1;