Farabi.pm

filter: Statementstmt 19.4% 14 / 72 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 50.0% 1 / 2 totaltotal 20.4% 18 / 88 CC 5 SCAR 19.8
CC
5
Cov
18%
support_can_be_enabled
12.0
startup
10.2
_setup_dirs
2.0
CRAP 7.3
« Farabi/Editor.pm ↑ Summary
1 package Farabi;
2  
3 2 ▶use Mojo::Base 'Mojolicious';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Modern Perl IDE
7 2 our $VERSION = '0.47'; # VERSION
8  
9  
10 # Application SQLite database and projects are stored in this directory
11 2 has 'home_dir';
12  
13 # Projects are stored in this directory
14 2 has 'projects_dir';
15  
16 # The database name and location
17 2 has 'db_name';
18  
19 1 ▶sub startup {
Subroutine startup: called CC=3 SCAR=23.3
Pod documented
20 1 my $app = shift;
21  
22 # Change secret passphrase that is used for signed cookies
23 1 $app->secrets( ['Hulk, Smash!'] );
24  
25 # Use content from directories under lib/Farabi/files
26 1 $app->home->parse( path( path(__FILE__)->dirname, 'Farabi' ) );
27 0 $app->static->paths->[0] = $app->home->rel_dir('files/public');
28 0 $app->renderer->paths->[0] = $app->home->rel_dir('files/templates');
29  
30 # Define routes
31 0 my $route = $app->routes;
32 0 $route->get('/')->to('editor#default');
33 0 $route->post("/syntax_check")->to('editor#syntax_check');
34 0 $route->post('/pod2html')->to('editor#pod2html');
35 0 $route->post("/md2html")->to('editor#md2html');
36 0 $route->post("/perl_critic")->to('editor#perl_critic');
37 0 $route->post("/perl_tidy")->to('editor#perl_tidy');
38 0 $route->post("/perl_strip")->to('editor#perl_strip');
39 0 $route->post("/spellunker")->to('editor#spellunker');
40 0 $route->post("/code_cutnpaste")->to('editor#code_cutnpaste');
41 0 $route->post("/git")->to('editor#git');
42 0 $route->post("/open_file")->to('editor#open_file');
43 0 $route->post("/save_file")->to('editor#save_file');
44 0 $route->post("/find_file")->to('editor#find_file');
45 0 $route->post("/find_action")->to('editor#find_action');
46 0 $route->post("/run_perl")->to('editor#run_perl');
47 0 $route->post("/run_perlbrew_exec")->to('editor#run_perlbrew_exec');
48 0 $route->post("/dump_ppi_tree")->to('editor#dump_ppi_tree');
49 0 $route->post("/repl_eval")->to('editor#repl_eval');
50 0 $route->post("/ping")->to('editor#ping');
51 0 $route->post("/ack")->to('editor#ack');
52 0 $route->post("/midgen")->to('editor#midgen');
53 0 $route->post("/project")->to('editor#project');
54 0 $route->post("/cpanm")->to('editor#cpanm');
55 0 $route->post("/help")->to('editor#help');
56  
57 0 eval { $app->_setup_dirs };
58 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
59 0 die "Failure to create \$HOME/.farabi directory structure, reason: $@";
60 }
61  
62 # The database name
63 0 $app->db_name( path( $app->home_dir, 'farabi.db' ) );
64  
65 # Setup the Farabi database
66 0 eval { $app->_setup_database };
67 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
68 0 warn "Database not setup, reason: $@";
69 }
70 }
71  
72  
73 0 ▶sub support_can_be_enabled {
Subroutine support_can_be_enabled: not called CC=3 SCAR=24.8
Pod undocumented
74 0 my $app = shift;
75 0 my $module = shift;
76  
77 0 my %REQUIRED_VERSION = (
78 'Perl::Critic' => '1.118',
79 'Perl::Tidy' => '20121207',
80 'Perl::Strip' => '1.1',
81 'Spellunker' => '0.0.17',
82 'Code::CutNPaste' => '0.04',
83 'App::Midgen' => '0.32',
84 'Dist::Zilla' => '5.016',
85 );
86  
87 0 my $version = $REQUIRED_VERSION{$module};
88 0 ▶ return 0 unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
89  
90 0 eval qq{use $module $version;};
91 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
92 0 $app->log->warn(
93 "$module support is disabled. Please install $module $version or later."
94 );
95 0 return 0;
96 }
97 else {
98 0 $app->log->info("$module support is enabled");
99 0 return 1;
100 }
101 }
102  
103 #
104 # Create the following directory structure:
105 # .farabi
106 # .farabi/projects
107 #
108 0 ▶sub _setup_dirs {
Subroutine _setup_dirs: not called CC=1 SCAR=6.9
109 0 my $app = shift;
110  
111 0 require File::HomeDir;
112  
113 0 $app->home_dir( path( File::HomeDir->home, ".farabi" ) );
114 0 $app->projects_dir( path( $app->home_dir, "projects" ) );
115 0 $app->projects_dir->mkpath;
116 }
117  
118 # Setup the Farabi database
119 0 ▶sub _setup_database {
Subroutine _setup_database: not called CC=1 SCAR=6.9
120 0 my $app = shift;
121  
122 # Connect and create the Farabi SQLite database if not found
123 0 require DBIx::Simple;
124 0 my $db_name = $app->db_name;
125 0 my $db = DBIx::Simple->connect("dbi:SQLite:dbname=$db_name");
126  
127 # Create tables if they do not exist
128 0 $db->query(<<SQL);
129 CREATE TABLE IF NOT EXISTS recent_list (
130 id INTEGER PRIMARY KEY AUTOINCREMENT,
131 name TEXT,
132 type TEXT,
133 last_used TEXT
134 )
135 SQL
136  
137 # Disconnect from database
138 0 $db->disconnect;
139 }
140  
141 2 1;
142  
143 __END__
« Farabi/Editor.pm ↑ Summary