File Coverage

blib/lib/Nephia/Setup/Plugin/Relax.pm
Criterion Covered Total %
statement 37 79 46.8
branch 0 2 0.0
condition n/a
subroutine 9 20 45.0
pod 2 13 15.3
total 48 114 42.1


line stmt bran cond sub pod time code
1             package Nephia::Setup::Plugin::Relax;
2 2     2   303117 use 5.008005;
  2         7  
  2         68  
3 2     2   11 use strict;
  2         4  
  2         60  
4 2     2   21 use warnings;
  2         4  
  2         55  
5 2     2   722 use parent 'Nephia::Setup::Plugin';
  2         315  
  2         14  
6 2     2   2843 use Data::Section::Simple 'get_data_section';
  2         518  
  2         134  
7 2     2   11 use File::Spec;
  2         3  
  2         72  
8 2     2   10 use File::Basename 'dirname';
  2         3  
  2         1759  
9              
10             our $VERSION = "0.02";
11              
12             sub bundle {
13 1     1 1 25 qw/Assets::Bootstrap Assets::JQuery/;
14             }
15              
16             sub fix_setup {
17 1     1 1 1039 my $self = shift;
18              
19 1         9 my $chain = $self->setup->action_chain;
20 1         20 $chain->{chain} = [];
21 1         10 $chain->append('CreateApproot' => $self->can('create_approot'));
22 1         150 $chain->append('CreatePSGI' => $self->can('create_psgi'));
23 1         108 $chain->append('CreateConfig' => $self->can('create_config'));
24 1         107 $chain->append('CreateAppClass' => $self->can('create_app_class'));
25 1         105 $chain->append('CreateSomeClasses' => $self->can('create_some_classes'));
26 1         116 $chain->append('CreateDBDir' => $self->can('create_db_dir'));
27 1         139 $chain->append('CreateTemplates' => $self->can('create_templates'));
28 1         125 $chain->append('CreateSQL' => $self->can('create_sql'));
29 1         135 $chain->append('CreateSetup' => $self->can('create_setup'));
30 1         125 $chain->append('CreateCPANFile' => $self->can('create_cpanfile'));
31              
32 1         142 push @{$self->setup->deps->{requires}}, (
  1         5  
33             'Plack::Middleware::Static' => '0',
34             'Plack::Middleware::Session' => '0',
35             'Plack::Middleware::CSRFBlock' => '0',
36             'Cache::Memcached::Fast' => '0',
37             'DBI' => '0',
38             'DBD::SQLite' => '0',
39             'Data::Page::Navigation' => '0',
40             'Otogiri' => '0',
41             'Nephia::Plugin::Dispatch' => '0.03',
42             'Nephia::Plugin::FillInForm' => '0',
43             'Nephia::Plugin::JSON' => '0.03',
44             'Nephia::Plugin::ResponseHandler' => '0',
45             'Nephia::Plugin::View::Xslate' => '0',
46             'Nephia::Plugin::ErrorPage' => '0',
47             'Nephia::Plugin::FormValidator::Lite' => '0',
48             'Nephia' => '0.87',
49             );
50             }
51              
52             sub load_data {
53 0     0 0   my ($class, $setup, @path) = @_;
54 0           my $str = get_data_section(@path);
55 0           $setup->process_template($str);
56             }
57              
58             sub create_approot {
59 0     0 0   my ($setup, $context) = @_;
60 0 0         $setup->stop(sprintf('%s is Already exists', $setup->approot)) if -d $setup->approot;
61 0           $setup->makepath('.');
62             }
63              
64             sub create_psgi {
65 0     0 0   my ($setup, $context) = @_;
66 0           my $data = __PACKAGE__->load_data($setup, 'app.psgi');
67 0           $setup->spew('app.psgi', $data);
68             }
69              
70             sub create_config {
71 0     0 0   my ($setup, $context) = @_;
72              
73 0           my $common = __PACKAGE__->load_data($setup, 'common.pl');
74 0           $setup->spew('config', 'common.pl', $common);
75              
76 0           $setup->{dbfile} = File::Spec->catfile('var', 'db.sqlite3');
77 0           my $data = __PACKAGE__->load_data($setup, 'config.pl');
78 0           for my $env (qw/local dev real/) {
79 0           $setup->spew('config', "$env.pl", $data);
80             }
81             }
82              
83             sub create_db_dir {
84 0     0 0   my ($setup, $context) = @_;
85 0           $setup->makepath('var');
86             }
87              
88             sub create_app_class {
89 0     0 0   my ($setup, $context) = @_;
90 0           my $data = __PACKAGE__->load_data($setup, 'MyClass.pm');
91 0           $setup->spew($setup->classfile, $data);
92             }
93              
94             sub create_some_classes {
95 0     0 0   my ($setup, $context) = @_;
96 0           for my $subclass ( qw/C::Root C::API::Member M M::DB M::DB::Member M::Cache/ ) {
97 0           $setup->{tmpclass} = join('::', $setup->appname, $subclass);
98 0           my $data = __PACKAGE__->load_data($setup, $subclass);
99 0           $setup->spew('lib', split('::', $setup->{tmpclass}.'.pm'), $data);
100             }
101             }
102              
103             sub create_templates {
104 0     0 0   my ($setup, $context) = @_;
105 0           for my $template ( qw/index include::layout include::navbar error/ ) {
106 0           my $file = File::Spec->catfile( split('::', $template) ). '.tt';
107 0           my $data = __PACKAGE__->load_data($setup, $file);
108 0           $setup->makepath('view', dirname($file));
109 0           $setup->spew('view', $file, $data);
110             }
111             }
112              
113             sub create_sql {
114 0     0 0   my ($setup, $context) = @_;
115 0           for my $type ( qw/ mysql sqlite / ) {
116 0           my $data = __PACKAGE__->load_data($setup, $type.'.sql');
117 0           $setup->spew('sql', $type.'.sql', $data);
118             }
119             }
120              
121             sub create_setup {
122 0     0 0   my ($setup, $context) = @_;
123 0           my $data = __PACKAGE__->load_data($setup, 'setup.sh');
124 0           $setup->spew('script', 'setup.sh', $data);
125 0           chmod 0755, File::Spec->catfile($setup->approot, qw/script setup.sh/);
126             }
127              
128             sub create_cpanfile {
129 0     0 0   my ($setup, $context) = @_;
130 0           $setup->spew('cpanfile', $setup->cpanfile);
131             }
132              
133             1;
134             __DATA__