File: Common.pm

package info (click to toggle)
swish-e 2.4.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,248 kB
  • ctags: 7,642
  • sloc: ansic: 47,385; sh: 8,502; perl: 5,101; makefile: 719; xml: 9
file content (77 lines) | stat: -rw-r--r-- 1,821 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package Pod::HtmlPsPdf::Common;

use strict;
use Symbol ();
use File::Basename ();
use File::Copy ();

use Pod::HtmlPsPdf::Config ();
my $config = Pod::HtmlPsPdf::Config->new();

### Common functions

# copy_file($src_filename,$dest_filename); $src_filename will be
# placed into the specified path, if one of the directories in the
# target path doesn't exist -- it'll be created.
###############
sub copy_file{
    my ($src,$dst) = @_;
    
    # make sure that the directory exist or create one
    
    my $base_dir = File::Basename::dirname $dst;
    create_dir($base_dir) unless (-d $base_dir);
    
    File::Copy::copy($src,$dst);
    
} # end of sub copy_file


# write_file($filename,$ref_to_array);
# content will be written to the file from the passed array of
# paragraphs
###############
sub write_file{
    my ($fn,$ra_content) = @_;
    
    # make sure that the directory exist or create one
    
    my $base_dir = File::Basename::dirname $fn;
    create_dir($base_dir) unless (-d $base_dir);
    
    my $fh = Symbol::gensym;
    open $fh, ">$fn" or die "Can't open $fn for writing: $!\n";
    print $fh @$ra_content;
    close $fh;

} # end of sub write_file


# recursively creates a multi-layer directory
###############
sub create_dir{
    my $dir = shift || '';
    return if !$dir or -d $dir;
    my $ancestor_dir = File::Basename::dirname $dir;
    create_dir($ancestor_dir);
    my $mode = $config->get_param('dir_mode');
    mkdir $dir, $mode;
}

# read_file_paras($filename,$ref_to_array);
# content will be returned in the passed array of paragraphs
###############
sub read_file{
  my ($fn,$ra_content) = @_;

  my $fh = Symbol::gensym;
  open $fh, $fn  or die "Can't open $fn for reading: $!\n";
  local $/ = "";
  @$ra_content = <$fh>;
  close $fh;

} # end of sub read_file


1;
__END__