Skip to content

Commit

Permalink
Client side: dzil Oyster plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hakim committed Nov 20, 2010
1 parent ce3563d commit 4aedd3b
Show file tree
Hide file tree
Showing 7 changed files with 484 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author = osfameron <osfameron@cpan.org>
license = Perl_5
copyright_holder = osfameron
copyright_year = 2010
copyright_holder = The Contributors

version = 0.001

Expand Down
76 changes: 76 additions & 0 deletions lib/Dist/Zilla/App/Command/provision.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use strict;
use warnings;
package Dist::Zilla::App::Command::provision;
BEGIN {
$Dist::Zilla::App::Command::provision::VERSION = '0.1';
}
# ABSTRACT: release your dist to the CPAN
use Dist::Zilla::App -command;
use Moose;
use Config::Any;

sub abstract { 'provision a new Oyster VM' }

sub opt_spec {
[ 'name|s' => 'the name of the VM to create' ],
}

sub execute {
my ($self, $opt, $arg) = @_;

my $zilla = $self->zilla;

my $name = $opt->name
or die "No name provided!";
my @config_files = ( './oyster.conf' ); # TODO make configurable

my $cfg = Config::Any->load_files({ files => \@config_files });
($cfg) = values %{ $cfg->[0] }; # FIX with ::JFDI or similar

my $Provision = $cfg->{Provision} or die "No <Provision> section";
my $target = $Provision->{$name} or die "No section for <Provision> <$name>";

my $type = $target->{type} || 'EC2';

use Oyster::Provision;
my $server = Oyster::Provision->new(
name => $name,
size => '256',
image => 'Meerkat',
pub_ssh => "$ENV{HOME}/.ssh/id_rsa.pub",
provision_backend => $type,
);
$server->create;
print "Instance $name created! ($server)\n";
}

1;

__END__
=pod
=head1 NAME
Dist::Zilla::App::Command::provision - provision a new Oyster VM
=head1 VERSION
version 0.1
=head1 SYNOPSIS
TODO
=head1 AUTHOR
CONTRIBUTORS
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by CONTRIBUTORS
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
58 changes: 58 additions & 0 deletions lib/Dist/Zilla/Plugin/Oyster.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use strict;
use warnings;
package Dist::Zilla::Plugin::Oyster;
BEGIN {
our $VERSION = 0.07;# VERSION
}
1;
# ABSTRACT: set of plugins for working with Oyster


__END__
=pod
=head1 NAME
Dist::Zilla::Plugin::Oyster - set of plugins for working with Oyster
=head1 VERSION
version 0.07
=head1 DESCRIPTION
The following is a list of plugins in this distribution to help you integrate
L<Oyster> and L<Dist::Zilla>
=over
=item * L<Dist::Zilla::Plugin::Oyster::New> Create a new Oyster Project
=back
=head1 PATCHES
Please read the SubmittingPatches file included with this Distribution. Patches
that are of sufficient quality, within the goals of the project and pass the
checklist will probably be accepted.
=head1 AUTHORS
=over 4
=item *
see README (TODO)
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2010 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0
=cut
89 changes: 89 additions & 0 deletions lib/Dist/Zilla/Plugin/Oyster/Helper.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use strict;
use warnings;
package Dist::Zilla::Plugin::Oyster::Helper;
BEGIN {
our $VERSION = 0.01;# VERSION
}
use Moose;
use Dist::Zilla::File::InMemory;

extends 'Catalyst::Helper';

has _zilla_gatherer => (
is => 'ro',
required => 1,
handles => {
_zilla_add_file => 'add_file',
},
);

# we don't want these to do anything
sub _mk_changes {};
sub _mk_makefile {};
sub _mk_readme {};
sub _mk_apptest {};
sub _mk_podtest {};
sub _mk_podcoveragetest {};

sub mk_file {
my ( $self, $file_obj , $output ) = @_;

# unfortunately the stringified $file_obj includes a prepended
# {dist_repo} name which dzil already creates if we don't regex it out we
# end up with {dist_repo}/{dist_repo}/{files} instead of just
# {dist_repo}/{files}
my $name = "$file_obj";
$name =~ s{[\w-]+/}{};

my $file
= Dist::Zilla::File::InMemory->new({
name => $name,
content => $output,
});

$file->mode( oct(755) ) if $file->name =~ /script/;

$self->_zilla_add_file($file);
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
# ABSTRACT: a subclass of Catalyst::Helper


__END__
=pod
=head1 NAME
Dist::Zilla::Plugin::Oyster::Helper - a subclass of Catalyst::Helper
=head1 VERSION
version 0.07
=head1 DESCRIPTION
this is used to override methods in L<Catalyst::Helper> so that it works
better with dzil.
=head1 AUTHORS
=over 4
=item *
CONTRIBUTORS TODO (note, based on xenoterracide & t0m's work)
=back
=head1 COPYRIGHT AND LICENSE
TODO
This is free software, licensed under:
The Artistic License 2.0
=cut
126 changes: 126 additions & 0 deletions lib/Dist/Zilla/Plugin/Oyster/New.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use strict;
use warnings;
package Dist::Zilla::Plugin::Oyster::New;
BEGIN {
our $VERSION = 0.01;# VERSION
}
use Moose;
use Dist::Zilla::Plugin::Oyster::Helper;
with qw( Dist::Zilla::Role::ModuleMaker );

use Dist::Zilla::File::FromCode;

sub make_module {
my ( $self ) = @_;

if ( $Catalyst::Helper::VERSION <= 1.28 ) {
$self->log('getting authors from ENV variable AUTHOR not dzil');
}

# format $name to what C::Helper wants
my $name = $self->zilla->name;
$name =~ s/-/::/g;

# turn authors into a scalar it's what C::Helper wants
my $authors = join( ',', @{$self->zilla->authors} );

my $helper
= Dist::Zilla::Plugin::Oyster::Helper->new({
name => $name,
author => $authors,
_zilla_gatherer => $self,
});

# $name here is for backcompat in older versions of C::Devel
$helper->mk_app( $name );
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
# ABSTRACT: create a new catalyst project with dzil new


__END__
=pod
=head1 NAME
Dist::Zilla::Plugin::Oyster::New - create a new Oyster project with dzil new
=head1 VERSION
version 0.07
=head1 SYNOPSIS
in C<{home}/.dzil/profiles/oyster/profile.ini>
[Oyster::New / :DefaultModuleMaker]
[@Oyster]
=head1 DESCRIPTION
this plugin is used to generate the same files L<Catalyst::Helper> does when
C<catalyst.pl App::Name> is run.
=head1 EXAMPLE
You probably want more than just the bare minimum profile.ini, here's a more
functional one. I suggest putting it in
C<{home}/.dzil/profiles/oyster/profile.ini>
[Oyster::New / :DefaultModuleMaker]
[@Oyster]
Now you can run the following command to create a skeleton catalyst app.
dzil new -p oyster MyApp
Obviously C<MyApp> is arbitrary and can be named whatever you like.
=head1 METHODS
=over
=item * make_module
required see L<Dist::Zilla::Role::ModuleMaker>
=back
=head1 BUGS
or features depending on your opinion and the nature of the issue. The
following are known "issue's".
=over
=item * Doesn't create all the files catalyst.pl does
Some files like README, Makefile.PL and some of the tests, etc, are better
generated by C<dzil>. Use existing dzil plugins to generate these.
=back
For all other problems use the bug tracker
=head1 AUTHORS
=over 4
=item *
TODO, see CONTRIBUTORS
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2010 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0
=cut
Loading

0 comments on commit 4aedd3b

Please sign in to comment.