Changeset 3667 for lang/perl/Archer

Show
Ignore:
Timestamp:
12/28/07 11:22:52 (7 years ago)
Author:
tokuhirom
Message:

r3362@mnk (orig r12): tokuhiro | 2006-10-05 20:43:17 -0700
an prototype.


Location:
lang/perl/Archer
Files:
15 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Archer/MANIFEST

    r3666 r3667  
     1.cvsignore 
    12Build.PL 
    23Changes 
     4lib/Archer.pm 
     5lib/Archer/ConfigLoader.pm 
     6lib/Archer/Parallel/ForkManager.pm 
     7lib/Archer/Plugin.pm 
     8lib/Archer/Plugin/Confirm.pm 
     9lib/Archer/Plugin/Exec.pm 
     10lib/Archer/Plugin/Exec/Local.pm 
     11lib/Archer/Plugin/Exec/Remote.pm 
     12lib/Archer/Plugin/MySQLDiff/Sledge.pm 
     13Makefile.PL 
    314MANIFEST 
    4 META.yml # Will be created by "make dist" 
    5 Makefile.PL 
     15META.yml                        # Will be created by "make dist" 
    616README 
    7 lib/Archer.pm 
    817t/00.load.t 
    918t/perlcritic.t 
  • lang/perl/Archer/lib/Archer.pm

    r3666 r3667  
    33use warnings; 
    44use Carp; 
    5 use version; 
     5use List::MoreUtils qw/uniq/; 
     6use Archer::ConfigLoader; 
     7use UNIVERSAL::require; 
     8use XXX; 
     9 
    610our $VERSION = 0.01; 
    711 
     12my $context; 
     13sub context { $context } 
     14sub set_context { 
     15    my ($class, $c) = @_; 
     16    $context = $c; 
     17} 
    818 
     19sub new { 
     20    my ($class, $opts) = @_; 
     21    my $self = bless {%$opts}, $class; 
    922 
    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 
     31sub run { 
     32    my ($self, ) = @_; 
     33 
     34    $self->run_hook('init'); 
     35 
     36    $self->run_process; 
     37 
     38    $self->run_hook('finalize'); 
     39} 
     40 
     41sub 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 
     60sub 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 
     85sub 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? 
     94sub log { 
     95    my ($self, $level, $msg) = @_; 
     96 
     97    carp "[$level] $msg"; 
     98} 
     99 
     1001; 
     101 
    11102__END__ 
    12103 
    13104=head1 NAME 
    14105 
    15 Archer - [One line description of module's purpose here] 
    16  
    17  
    18 =head1 VERSION 
    19  
    20 This document describes Archer version 0.0.1 
    21  
     106Archer -  
    22107 
    23108=head1 SYNOPSIS 
    24109 
    25     use Archer; 
    26110 
    27 =for author to fill in: 
    28     Brief code example(s) here showing commonest usage(s). 
    29     This section will be as far as many users bother reading 
    30     so make it as educational and exeplary as possible. 
    31    
    32    
     111 
    33112=head1 DESCRIPTION 
    34113 
    35 =for author to fill in: 
    36     Write a full description of the module and its features here. 
    37     Use subsections (=head2, =head3) as appropriate. 
     114=head1 AUTHORS 
    38115 
     116Tokuhiro Matsuno 
    39117 
    40 =head1 INTERFACE  
     118=head1 TODO 
    41119 
    42 =for author to fill in: 
    43     Write a separate section listing the public components of the modules 
    44     interface. These normally consist of either subroutines that may be 
    45     exported, or methods that may be called on objects belonging to the 
    46     classes provided by the module. 
     120=cut 
    47121 
    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.