| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Template::Plugin::File |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Plugin for encapsulating information about a system file. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# AUTHOR |
|
9
|
|
|
|
|
|
|
# Originally written by Michael Stevens as the |
|
10
|
|
|
|
|
|
|
# Directory plugin, then mutilated by Andy Wardley |
|
11
|
|
|
|
|
|
|
# into separate File and Directory plugins, with some additional |
|
12
|
|
|
|
|
|
|
# code for working with views, etc. |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# COPYRIGHT |
|
15
|
|
|
|
|
|
|
# Copyright 2000-2007 Michael Stevens, Andy Wardley. |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
18
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
#============================================================================ |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Template::Plugin::File; |
|
23
|
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
326
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
41
|
|
|
25
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
35
|
|
|
26
|
2
|
|
|
2
|
|
6
|
use Cwd; |
|
|
2
|
|
|
|
|
0
|
|
|
|
2
|
|
|
|
|
77
|
|
|
27
|
2
|
|
|
2
|
|
6
|
use File::Spec; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
25
|
|
|
28
|
2
|
|
|
2
|
|
5
|
use File::Basename; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
85
|
|
|
29
|
2
|
|
|
2
|
|
4
|
use base 'Template::Plugin'; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
527
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = 2.71; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our @STAT_KEYS = qw( dev ino mode nlink uid gid rdev size |
|
34
|
|
|
|
|
|
|
atime mtime ctime blksize blocks ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
38
|
|
|
|
|
|
|
# new($context, $file, \%config) |
|
39
|
|
|
|
|
|
|
# |
|
40
|
|
|
|
|
|
|
# Create a new File object. Takes the pathname of the file as |
|
41
|
|
|
|
|
|
|
# the argument following the context and an optional |
|
42
|
|
|
|
|
|
|
# hash reference of configuration parameters. |
|
43
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
|
46
|
104
|
100
|
|
104
|
1
|
200
|
my $config = ref($_[-1]) eq 'HASH' ? pop(@_) : { }; |
|
47
|
104
|
|
|
|
|
108
|
my ($class, $context, $path) = @_; |
|
48
|
104
|
|
|
|
|
60
|
my ($root, $home, @stat, $abs); |
|
49
|
|
|
|
|
|
|
|
|
50
|
104
|
100
|
66
|
|
|
403
|
return $class->throw('no file specified') |
|
51
|
|
|
|
|
|
|
unless defined $path and length $path; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# path, dir, name, root, home |
|
54
|
|
|
|
|
|
|
|
|
55
|
103
|
100
|
|
|
|
448
|
if (File::Spec->file_name_is_absolute($path)) { |
|
|
|
100
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
2
|
$root = ''; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif (($root = $config->{ root })) { |
|
59
|
|
|
|
|
|
|
# strip any trailing '/' from root |
|
60
|
30
|
|
|
|
|
33
|
$root =~ s[/$][]; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
71
|
|
|
|
|
53
|
$root = ''; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
103
|
|
|
|
|
1642
|
my ($name, $dir, $ext) = fileparse($path, '\.\w+'); |
|
67
|
|
|
|
|
|
|
# fixup various items |
|
68
|
103
|
|
|
|
|
236
|
$dir =~ s[/$][]; |
|
69
|
103
|
100
|
|
|
|
160
|
$dir = '' if $dir eq '.'; |
|
70
|
103
|
|
|
|
|
81
|
$name = $name . $ext; |
|
71
|
103
|
|
|
|
|
85
|
$ext =~ s/^\.//g; |
|
72
|
|
|
|
|
|
|
|
|
73
|
103
|
|
|
|
|
433
|
my @fields = File::Spec->splitdir($dir); |
|
74
|
103
|
100
|
100
|
|
|
325
|
shift @fields if @fields && ! length $fields[0]; |
|
75
|
103
|
|
|
|
|
190
|
$home = join('/', ('..') x @fields); |
|
76
|
103
|
100
|
|
|
|
453
|
$abs = File::Spec->catfile($root ? $root : (), $path); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $self = { |
|
79
|
|
|
|
|
|
|
path => $path, |
|
80
|
|
|
|
|
|
|
name => $name, |
|
81
|
|
|
|
|
|
|
root => $root, |
|
82
|
|
|
|
|
|
|
home => $home, |
|
83
|
|
|
|
|
|
|
dir => $dir, |
|
84
|
|
|
|
|
|
|
ext => $ext, |
|
85
|
|
|
|
|
|
|
abs => $abs, |
|
86
|
|
|
|
|
|
|
user => '', |
|
87
|
|
|
|
|
|
|
group => '', |
|
88
|
|
|
|
|
|
|
isdir => '', |
|
89
|
|
|
|
|
|
|
stat => defined $config->{ stat } |
|
90
|
|
|
|
|
|
|
? $config->{ stat } |
|
91
|
|
|
|
|
|
|
: ! $config->{ nostat }, |
|
92
|
103
|
50
|
|
|
|
242
|
map { ($_ => '') } @STAT_KEYS, |
|
|
1339
|
|
|
|
|
1817
|
|
|
93
|
|
|
|
|
|
|
}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
103
|
100
|
|
|
|
232
|
if ($self->{ stat }) { |
|
96
|
94
|
100
|
|
|
|
1329
|
(@stat = stat( $abs )) |
|
97
|
|
|
|
|
|
|
|| return $class->throw("$abs: $!"); |
|
98
|
|
|
|
|
|
|
|
|
99
|
93
|
|
|
|
|
356
|
@$self{ @STAT_KEYS } = @stat; |
|
100
|
|
|
|
|
|
|
|
|
101
|
93
|
50
|
|
|
|
132
|
unless ($config->{ noid }) { |
|
102
|
93
|
50
|
|
|
|
81
|
$self->{ user } = eval { getpwuid( $self->{ uid }) || $self->{ uid } }; |
|
|
93
|
|
|
|
|
4851
|
|
|
103
|
93
|
50
|
|
|
|
107
|
$self->{ group } = eval { getgrgid( $self->{ gid }) || $self->{ gid } }; |
|
|
93
|
|
|
|
|
2683
|
|
|
104
|
|
|
|
|
|
|
} |
|
105
|
93
|
|
|
|
|
992
|
$self->{ isdir } = -d $abs; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
102
|
|
|
|
|
462
|
bless $self, $class; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#------------------------------------------------------------------------- |
|
113
|
|
|
|
|
|
|
# rel($file) |
|
114
|
|
|
|
|
|
|
# |
|
115
|
|
|
|
|
|
|
# Generate a relative filename for some other file relative to this one. |
|
116
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub rel { |
|
119
|
2
|
|
|
2
|
1
|
4
|
my ($self, $path) = @_; |
|
120
|
2
|
100
|
|
|
|
6
|
$path = $path->{ path } if ref $path eq ref $self; # assumes same root |
|
121
|
2
|
50
|
|
|
|
5
|
return $path if $path =~ m[^/]; |
|
122
|
2
|
50
|
|
|
|
7
|
return $path unless $self->{ home }; |
|
123
|
2
|
|
|
|
|
9
|
return $self->{ home } . '/' . $path; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
128
|
|
|
|
|
|
|
# present($view) |
|
129
|
|
|
|
|
|
|
# |
|
130
|
|
|
|
|
|
|
# Present self to a Template::View. |
|
131
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub present { |
|
134
|
7
|
|
|
7
|
0
|
8
|
my ($self, $view) = @_; |
|
135
|
7
|
|
|
|
|
27
|
$view->view_file($self); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub throw { |
|
140
|
1
|
|
|
1
|
0
|
2
|
my ($self, $error) = @_; |
|
141
|
1
|
|
|
|
|
9
|
die (Template::Exception->new('File', $error)); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |