File Coverage

blib/lib/Dancer2/Plugin/EditFile.pm
Criterion Covered Total %
statement 24 65 36.9
branch 0 14 0.0
condition 0 6 0.0
subroutine 8 11 72.7
pod 0 3 0.0
total 32 99 32.3


line stmt bran cond sub pod time code
1             package Dancer2::Plugin::EditFile;
2              
3 1     1   45731 use warnings;
  1         1  
  1         24  
4 1     1   3 use strict;
  1         1  
  1         14  
5 1     1   3 use Carp;
  1         3  
  1         46  
6 1     1   404 use File::Copy "cp";
  1         3175  
  1         44  
7 1     1   4 use File::Basename;
  1         1  
  1         45  
8 1     1   408 use Try::Tiny;
  1         955  
  1         47  
9              
10 1     1   411 use Dancer2::Core::Types qw(Bool HashRef Str);
  1         7567  
  1         93  
11 1     1   483 use Dancer2::Plugin;
  1         40244  
  1         4  
12              
13             =head1 NAME
14              
15             Dancer2::Plugin::EditFile - Edit a text file from Dancer2
16              
17              
18             =head1 VERSION
19              
20             Version 0.005
21              
22              
23             =cut
24              
25             our $VERSION = '0.005';
26              
27             =head1 SYNOPSIS
28              
29             use Dancer2;
30             use Dancer2::Plugin::EditFile;
31              
32              
33             =head1 DESCRIPTION
34              
35             This plugin will allow you to retrieve a text file using Dancer2 and display it in an html page. Also, it will save the edited file to it's location on the server.
36              
37             It's designed to be flexible and unobtrusive. It's behavior is customizable through Dancer's config file. ration file to activate or deactivate files that may be edited. Just include it in your Dancer2 script, set the configuration and use it.
38              
39             B
40              
41             =over 4
42              
43             B
44              
45             There is a sample template in the sample folder.
46              
47             =back
48              
49             =head1 CONFIGURATION
50              
51             You may specify the routes and access to files. The plugin will only read/write files if it has access to them. The following configuration will generate two routes: '/editfile/display' and '/editfile/save'.
52              
53             A sample HTML page with Bootstrap and jQuery is included in the samples directory. Use it as an example to build your own page.
54              
55             plugins:
56             EditFile:
57             backup: 1
58             backup_dir: '/var/application/backups'
59             display:
60             method: 'get'
61             route: '/editfile/display'
62             template: 'editfile.tt'
63             layout: 'nomenu.tt'
64             save:
65             method: 'get'
66             route: '/editfile/save'
67             files:
68             id1:
69             heading: 'Edit Config.yml'
70             file: '/var/application/config.yml'
71             save: 1
72             id2:
73             heading: 'View config script config2'
74             file: '/var/application/config2.txt'
75             save: 0
76             id3:
77             heading: 'View XML file config3.xml'
78             file: '/var/application/config3.xml'
79             save: 0
80            
81             =over 4
82              
83             B the user B have read/write access to the file being edited and the backup directory.
84              
85             =back
86              
87             =over 4
88              
89             =item I
90              
91             Specify if original file should be saved. Default = 0 (do not save)
92              
93             =item I
94              
95             Directory where original files should be saved. Default = /tmp
96              
97             =item I
98              
99             Defines display settings.
100              
101             =over 4
102              
103             =item I
104              
105             Default 'get'.
106              
107             =item I
108              
109             Route in Dancer to display template and file contents for editing/viewing. Default '/editfile/display'
110              
111             =item I