| 10 | | 1; # Magic true value required at end of module |
| | 23 | my $config_loader = Archer::ConfigLoader->new; |
| | 24 | $self->{config} = $config_loader->load($opts->{config_yaml}); |
| | 25 | |
| | 26 | Archer->set_context($self); |
| | 27 | |
| | 28 | return $self; |
| | 29 | } |
| | 30 | |
| | 31 | sub run { |
| | 32 | my ($self, ) = @_; |
| | 33 | |
| | 34 | $self->run_hook('init'); |
| | 35 | |
| | 36 | $self->run_process; |
| | 37 | |
| | 38 | $self->run_hook('finalize'); |
| | 39 | } |
| | 40 | |
| | 41 | sub run_hook { |
| | 42 | my ($self, $hook, $args) = @_; |
| | 43 | $args ||= {}; |
| | 44 | |
| | 45 | $self->log('info' => "run hook $hook"); |
| | 46 | for my $plugin (@{ $self->{config}->{tasks}->{$hook} }) { |
| | 47 | my $class = "Archer::Plugin::$plugin->{module}"; |
| | 48 | $self->log('debug' => "load $class"); |
| | 49 | $class->use or die $@; |
| | 50 | |
| | 51 | $self->log('info' => "run $class"); |
| | 52 | $class->new( |
| | 53 | { config => $plugin->{config}, project => $self->{project}, %$args } ) |
| | 54 | ->run( $self, $args ); |
| | 55 | |
| | 56 | print "\n\n"; # for debug. |
| | 57 | } |
| | 58 | } |
| | 59 | |
| | 60 | sub run_process { |
| | 61 | my ($self) = @_; |
| | 62 | |
| | 63 | my $parallel = $self->{config}->{global}->{parallel} || 'Archer::Parallel::ForkManager'; |
| | 64 | $parallel->use or die $@; |
| | 65 | |
| | 66 | my $server_tree = $self->{config}->{projects}->{$self->{project}}; |
| | 67 | my @elems; |
| | 68 | while (my ($role, $servers) = each %$server_tree) { |
| | 69 | for my $server (@$servers) { |
| | 70 | push @elems, {server => $server, role => $role}; |
| | 71 | } |
| | 72 | } |
| | 73 | |
| | 74 | my $manager = $parallel->new; |
| | 75 | $manager->run( |
| | 76 | { elems => \@elems, |
| | 77 | callback => sub { |
| | 78 | my $args = shift; |
| | 79 | $self->run_hook( 'process', $args ); |
| | 80 | } |
| | 81 | } |
| | 82 | ); |
| | 83 | } |
| | 84 | |
| | 85 | sub bootstrap { |
| | 86 | my ($class, $opts) = @_; |
| | 87 | |
| | 88 | my $self = $class->new($opts); |
| | 89 | $self->run; |
| | 90 | return $self; |
| | 91 | } |
| | 92 | |
| | 93 | # TODO: use the log4perl? |
| | 94 | sub log { |
| | 95 | my ($self, $level, $msg) = @_; |
| | 96 | |
| | 97 | carp "[$level] $msg"; |
| | 98 | } |
| | 99 | |
| | 100 | 1; |
| | 101 | |
| 48 | | |
| 49 | | =head1 DIAGNOSTICS |
| 50 | | |
| 51 | | =for author to fill in: |
| 52 | | List every single error and warning message that the module can |
| 53 | | generate (even the ones that will "never happen"), with a full |
| 54 | | explanation of each problem, one or more likely causes, and any |
| 55 | | suggested remedies. |
| 56 | | |
| 57 | | =over |
| 58 | | |
| 59 | | =item C<< Error message here, perhaps with %s placeholders >> |
| 60 | | |
| 61 | | [Description of error here] |
| 62 | | |
| 63 | | =item C<< Another error message here >> |
| 64 | | |
| 65 | | [Description of error here] |
| 66 | | |
| 67 | | [Et cetera, et cetera] |
| 68 | | |
| 69 | | =back |
| 70 | | |
| 71 | | |
| 72 | | =head1 CONFIGURATION AND ENVIRONMENT |
| 73 | | |
| 74 | | =for author to fill in: |
| 75 | | A full explanation of any configuration system(s) used by the |
| 76 | | module, including the names and locations of any configuration |
| 77 | | files, and the meaning of any environment variables or properties |
| 78 | | that can be set. These descriptions must also include details of any |
| 79 | | configuration language used. |
| 80 | | |
| 81 | | Archer requires no configuration files or environment variables. |
| 82 | | |
| 83 | | |
| 84 | | =head1 DEPENDENCIES |
| 85 | | |
| 86 | | =for author to fill in: |
| 87 | | A list of all the other modules that this module relies upon, |
| 88 | | including any restrictions on versions, and an indication whether |
| 89 | | the module is part of the standard Perl distribution, part of the |
| 90 | | module's distribution, or must be installed separately. ] |
| 91 | | |
| 92 | | None. |
| 93 | | |
| 94 | | |
| 95 | | =head1 INCOMPATIBILITIES |
| 96 | | |
| 97 | | =for author to fill in: |
| 98 | | A list of any modules that this module cannot be used in conjunction |
| 99 | | with. This may be due to name conflicts in the interface, or |
| 100 | | competition for system or program resources, or due to internal |
| 101 | | limitations of Perl (for example, many modules that use source code |
| 102 | | filters are mutually incompatible). |
| 103 | | |
| 104 | | None reported. |
| 105 | | |
| 106 | | |
| 107 | | =head1 BUGS AND LIMITATIONS |
| 108 | | |
| 109 | | =for author to fill in: |
| 110 | | A list of known problems with the module, together with some |
| 111 | | indication Whether they are likely to be fixed in an upcoming |
| 112 | | release. Also a list of restrictions on the features the module |
| 113 | | does provide: data types that cannot be handled, performance issues |
| 114 | | and the circumstances in which they may arise, practical |
| 115 | | limitations on the size of data sets, special cases that are not |
| 116 | | (yet) handled, etc. |
| 117 | | |
| 118 | | No bugs have been reported. |
| 119 | | |
| 120 | | Please report any bugs or feature requests to |
| 121 | | C<bug-archer@rt.cpan.org>, or through the web interface at |
| 122 | | L<http://rt.cpan.org>. |
| 123 | | |
| 124 | | |
| 125 | | =head1 AUTHOR |
| 126 | | |
| 127 | | Tokuhiro Matsuno C<< <tokuhiro __at__ mobilefactory.jp> >> |
| 128 | | |
| 129 | | |
| 130 | | =head1 LICENCE AND COPYRIGHT |
| 131 | | |
| 132 | | Copyright (c) 2006, Tokuhiro Matsuno C<< <tokuhiro __at__ mobilefactory.jp> >>. All rights reserved. |
| 133 | | |
| 134 | | This module is free software; you can redistribute it and/or |
| 135 | | modify it under the same terms as Perl itself. See L<perlartistic>. |
| 136 | | |
| 137 | | |
| 138 | | =head1 DISCLAIMER OF WARRANTY |
| 139 | | |
| 140 | | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
| 141 | | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
| 142 | | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
| 143 | | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
| 144 | | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 145 | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
| 146 | | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
| 147 | | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
| 148 | | NECESSARY SERVICING, REPAIR, OR CORRECTION. |
| 149 | | |
| 150 | | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
| 151 | | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
| 152 | | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
| 153 | | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
| 154 | | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
| 155 | | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
| 156 | | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
| 157 | | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
| 158 | | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
| 159 | | SUCH DAMAGES. |