1Dancer::FileUtils(3)  User Contributed Perl Documentation Dancer::FileUtils(3)
2
3
4

NAME

6       Dancer::FileUtils - helper providing file utilities
7

VERSION

9       version 1.3513
10

SYNOPSIS

12           use Dancer::FileUtils qw/dirname path/;
13
14           # for 'path/to/file'
15           my $dir  = dirname($path); # returns 'path/to'
16           my $path = path($path);    # returns '/abs/path/to/file'
17
18
19           use Dancer::FileUtils qw/path read_file_content/;
20
21           my $content = read_file_content( path( 'folder', 'folder', 'file' ) );
22           my @content = read_file_content( path( 'folder', 'folder', 'file' ) );
23
24           use Dancer::FileUtils qw/read_glob_content set_file_mode/;
25
26           open my $fh, '<', $file or die "$!\n";
27           set_file_mode($fh);
28           my @content = read_file_content($fh);
29           my $content = read_file_content($fh);
30

DESCRIPTION

32       Dancer::FileUtils includes a few file related utilities related that
33       Dancer uses internally. Developers may use it instead of writing their
34       own file reading subroutines or using additional modules.
35

SUBROUTINES/METHODS

37   dirname
38           use Dancer::FileUtils 'dirname';
39
40           my $dir = dirname($path);
41
42       Exposes File::Basename's dirname, to allow fetching a directory name
43       from a path. On most OS, returns all but last level of file path. See
44       File::Basename for details.
45
46   open_file
47           use Dancer::FileUtils 'open_file';
48           my $fh = open_file('<', $file) or die $message;
49
50       Calls open and returns a filehandle. Takes in account the 'charset'
51       setting from Dancer's configuration to open the file in the proper
52       encoding (or defaults to utf-8 if setting not present).
53
54   path
55           use Dancer::FileUtils 'path';
56
57           my $path = path( 'folder', 'folder', 'filename');
58
59       Provides comfortable path resolving, internally using File::Spec.
60
61   read_file_content
62           use Dancer::FileUtils 'read_file_content';
63
64           my @content = read_file_content($file);
65           my $content = read_file_content($file);
66
67       Returns either the content of a file (whose filename is the input),
68       undef if the file could not be opened.
69
70       In array context it returns each line (as defined by $/) as a separate
71       element; in scalar context returns the entire contents of the file.
72
73   read_glob_content
74           use Dancer::FileUtils 'read_glob_content';
75
76           open my $fh, '<', $file or die "$!\n";
77           my @content = read_glob_content($fh);
78           my $content = read_glob_content($fh);
79
80       Same as read_file_content, only it accepts a file handle. Returns the
81       content and closes the file handle.
82
83   set_file_mode
84           use Dancer::FileUtils 'set_file_mode';
85
86           set_file_mode($fh);
87
88       Applies charset setting from Dancer's configuration. Defaults to utf-8
89       if no charset setting.
90

EXPORT

92       Nothing by default. You can provide a list of subroutines to import.
93

AUTHOR

95       Dancer Core Developers
96
98       This software is copyright (c) 2010 by Alexis Sukrieh.
99
100       This is free software; you can redistribute it and/or modify it under
101       the same terms as the Perl 5 programming language system itself.
102
103
104
105perl v5.30.1                      2020-02-05              Dancer::FileUtils(3)
Impressum