File Coverage

blib/lib/Class/Component/Recipe.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Class::Component::Recipe - Dynamic Component Containers
4              
5             =cut
6              
7             package Class::Component::Recipe;
8 1     1   774 use warnings;
  1         2  
  1         31  
9 1     1   4 use strict;
  1         2  
  1         27  
10              
11 1     1   386 use Moose::Policy 'Moose::Policy::FollowPBP';
  0            
  0            
12             use Moose;
13              
14             use aliased 'Class::Component::Recipe::Collection';
15              
16             our $VERSION = '0.01_02';
17              
18             =head1 SYNOPSIS
19              
20             use Class::Component::Recipe;
21              
22             # Create a new C:C:R object. Most work is done in the collection
23             my $ccr = Class::Component::Recipe->new(base_class => 'Foo::Base');
24             my $col = $ccr->get_collection;
25              
26             # Prepare the class list as you need it. See the Collection pod.
27             $col->push('Foo::ComponentA');
28             $col->push('Foo::ComponentB');
29             $col->insert('Foo::Middle', 1);
30              
31             # Install. @MyApp::Foo::ISA is now: Foo::ComponentB, Foo::Middle,
32             # Foo::ComponentA, Foo::Base. Previously existing entries will be
33             # before Foo::Base.
34             $ccr->install('MyApp::Foo');
35              
36             =head1 DESCRIPTION
37              
38             This module provides functionality to build a collection of classes
39             and install it together with a base in a container class. This
40             allows the dynamic creation of component based classes.
41              
42             =head1 ATTRIBUTES
43              
44             =head2 (get_|set_|has_)base_class
45              
46             The base class of the component container to build.
47              
48             =cut
49              
50             has 'base_class',
51             is => 'rw', isa => 'Str', predicate => 'has_base_class',
52             ;
53              
54             =head2 (get_|set_|has_)collection
55              
56             The collection object handling component order and installing the
57             final container.
58              
59             =cut
60              
61             has 'collection',
62             is => 'rw', isa => 'Object', predicate => 'has_collection',
63             ;
64              
65             =head2 (get_|set_)collection_class
66              
67             The class name of the collection object this recipe will produce.
68              
69             =cut
70              
71             has 'collection_class',
72             is => 'rw', isa => 'Str', default => Collection,
73             ;
74              
75             =head1 METHODS
76              
77             =head2 BUILD($param)
78              
79             L<Moose> method. Initializes C<collection> if not passed to
80             constructor.
81              
82             =cut
83              
84             sub BUILD {
85             my ($self, $param) = @_;
86              
87             unless ($self->has_collection) {
88             $self->set_collection($self->get_collection_class->new);
89             }
90             }
91              
92             =head2 install($target_class)
93              
94             Installs the collection and the base class into the C<$target_class>.
95              
96             =cut
97              
98             sub install {
99             my ($self, $target_class) = @_;
100             return $self->get_collection
101             ->install($target_class, $self->get_base_class);
102             }
103              
104             =head1 SEE ALSO
105              
106             L<Class::Component::Recipe::Collection> for the collection interface.
107             L<NEXT>, L<C3> for component designing systems with multiple inheritance.
108              
109             =head1 REQUIRES
110              
111             L<aliased>, L<Class::Inspector>, L<Carp::Clan>, L<Moose>, L<Moose::Policy>,
112             L<Test::More> (for build).
113              
114             =head1 AUTHOR
115              
116             Robert 'phaylon' Sedlacek C<E<lt>phaylon@dunkelheit.atE<gt>>
117              
118             =head1 LICENSE AND COPYRIGHT
119              
120             This program is free software, you can redistribute it and/or modify it
121             under the same terms as Perl itself.
122              
123             =cut
124              
125             1;