File Coverage

lib/Egg/Manager/Model.pm
Criterion Covered Total %
statement 9 34 26.4
branch 0 4 0.0
condition 0 2 0.0
subroutine 3 12 25.0
pod n/a
total 12 52 23.0


line stmt bran cond sub pod time code
1             package Egg::Manager::Model;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: Model.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   498 use strict;
  1         2  
  1         38  
8 1     1   7 use warnings;
  1         3  
  1         423  
9              
10             our $VERSION= '3.00';
11              
12             my $handler= 'Egg::Manager::Model::handler';
13              
14             sub init_model {
15 0     0     my($class)= @_;
16 0           $handler->initialize('model');
17 0 0         $class->mk_classdata('model_manager') unless $class->can('model_manager');
18 0           $class;
19             }
20             sub setup_model {
21 0     0     my($e)= @_;
22 0           $e->model_manager($handler->new($e))->setup_manager;
23             }
24             sub model {
25 0     0     shift->model_manager->context(@_);
26             }
27             sub is_model {
28 0     0     my $e= shift;
29 0   0       my $label= lc(shift) || return 0;
30 0 0         $e->model_manager->regists->{$label} ? $label: 0;
31             }
32             sub _prepare {
33 0     0     my($e)= @_;
34 0           $e->model_manager->_prepare($e);
35 0           $e->next::method;
36             }
37             sub _finalize {
38 0     0     my($e)= @_;
39 0           $e->model_manager->_finalize($e);
40 0           $e->next::method;
41             }
42             sub _finalize_error {
43 0     0     my($e)= @_;
44 0           $e->model_manager->_finalize_error($e);
45 0           $e->next::method;
46             }
47             sub _output {
48 0     0     my($e)= @_;
49 0           $e->model_manager->_output($e);
50 0           $e->next::method;
51             }
52             sub _finish {
53 0     0     my($e)= @_;
54 0           $e->model_manager->_finish($e);
55 0           $e->next::method;
56             }
57              
58             package Egg::Manager::Model::handler;
59 1     1   7 use base qw/ Egg::Manager /;
  1         3  
  1         61  
60              
61             1;
62              
63             __END__
64              
65             =head1 NAME
66              
67             Egg::Manager::Model - Model manager for Egg.
68              
69             =head1 DESCRIPTION
70              
71             It is a module to offer Egg the model function.
72              
73             When the model_manager method of Egg is called, the handler class for the model
74             is returned.
75              
76             =head1 CONFIGURATION
77              
78             The configuration of the model is done to 'MODEL' by the ARRAY form.
79              
80             MODEL => [
81             [ DBI => {
82             dsn => ...........
83             ..........
84             } ],
85             ],
86              
87             =head1 METHODS
88              
89             Because this class is registered in @ISA of the project, the method can be used
90             directly from the object of the project.
91              
92             $project->model( .... );
93              
94             =head2 init_model
95              
96             When starting for the model, it initializes it.
97              
98             =head2 setup_model
99              
100             The setup for the model is done.
101              
102             =head2 model ([LABEL_STRING])
103              
104             The object of the specific model specified with LABEL_STRING is returned.
105              
106             When LABEL_STRING is omitted, the object of the model of default is restored.
107              
108             my $dbi= $e->model;
109             or
110             my $dbi= $e->model('dbi::main');
111              
112             The setting of the first element set to the configuration becomes default.
113              
114             L<Egg::Model::DBI> is attached to the model.
115              
116             =head2 is_model ([LABEL_STRING])
117              
118             If the model corresponding to LABEL_STRING can be used, true is returned.
119              
120             unless ($e->is_model('dbi')) {
121             die q{ dbi is not active. };
122             }
123              
124             =head1 HANDLER METHODS
125              
126             It is model manager's main body.
127              
128             L<Egg::Manager> is succeeded to and the main function is used.
129              
130             The method is called by way of model_manager.
131              
132             This class is succeeding to L<Egg::Manager> and it doesn't have a peculiar method.
133              
134             =head1 SEE ALSO
135              
136             L<Egg::Release>,
137             L<Egg::Manager>,
138             L<Egg::Model::DBI>,
139              
140             =head1 AUTHOR
141              
142             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
147              
148             This library is free software; you can redistribute it and/or modify
149             it under the same terms as Perl itself, either Perl version 5.8.6 or,
150             at your option, any later version of Perl 5 you may have available.
151              
152             =cut
153