Created
April 28, 2011 07:50
-
-
Save akiym/945984 to your computer and use it in GitHub Desktop.
Amon2::Setup::Flavor::Teng
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
package Amon2::Setup::Flavor::Teng; | |
use parent qw(Amon2::Setup::Flavor::Basic); | |
sub run { | |
my $self = shift; | |
$self->SUPER::run(); | |
$self->write_file('lib/<<PATH>>.pm', <<'...'); | |
package <% $module %>; | |
use strict; | |
use warnings; | |
use parent qw/Amon2/; | |
our $VERSION='0.01'; | |
use 5.008001; | |
__PACKAGE__->load_plugin(qw/DBI/); | |
use Teng; | |
use Teng::Schema::Loader; | |
sub db { | |
my $self = shift; | |
if (!defined $self->{db}) { | |
my $dbh = $self->dbh; | |
my $schema = Teng::Schema::Loader->load( | |
dbh => $dbh, | |
namespace => '<% $module %>::DB', | |
); | |
$self->{db} = Teng->new( | |
dbh => $dbh, | |
schema => $schema, | |
); | |
} | |
return $self->{db}; | |
} | |
1; | |
... | |
$self->write_file('lib/<<PATH>>/DB.pm', <<'...'); | |
package <% $module %>::DB; | |
use parent 'Teng'; | |
1; | |
... | |
$self->write_file('lib/<<PATH>>/DB/Schema.pm', ''); | |
$self->write_file('script/make_schema.pl', <<'...'); | |
use strict; | |
use warnings; | |
use File::Spec; | |
use File::Basename; | |
use lib File::Spec->catdir(dirname(__FILE__), '..', 'extlib', 'lib', 'perl5'); | |
use lib File::Spec->catdir(dirname(__FILE__), '..', 'lib'); | |
use <% $module %>; | |
use Teng::Schema::Dumper; | |
my $c = <% $module %>->bootstrap; | |
my $schema = Teng::Schema::Dumper->dump( | |
dbh => $c->dbh, | |
namespace => '<% $module %>::DB', | |
); | |
my $dest = File::Spec->catfile(dirname(__FILE__), '..', 'lib', '<% $module %>', 'DB', 'Schema.pm'); | |
open my $fh, '>', $dest or die "Cannot open file: $dest: $!"; | |
print {$fh} $schema; | |
close $fh; | |
... | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment