line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# Simple.pm |
3
|
|
|
|
|
|
|
# Copyright (c) 2006 Jonathan Rockway |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# see POD after __END__ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package File::Attributes::Simple; |
8
|
11
|
|
|
11
|
|
246479
|
use strict; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
386
|
|
9
|
11
|
|
|
11
|
|
55
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
332
|
|
10
|
11
|
|
|
11
|
|
76
|
use base qw(File::Attributes::Base); |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
5132
|
|
11
|
11
|
|
|
11
|
|
15188
|
use Best [ [ qw/YAML::Syck YAML/ ], qw/DumpFile LoadFile/ ]; |
|
11
|
|
|
|
|
80353
|
|
|
11
|
|
|
|
|
102
|
|
12
|
11
|
|
|
11
|
|
144050
|
use File::Spec; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
12685
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub priority { |
17
|
5
|
|
|
5
|
1
|
64
|
return 1; # try something else first, eh? |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub applicable { |
21
|
29
|
|
|
29
|
1
|
135
|
return 1; # this module Works Everywhere, hopefully. |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _load { |
25
|
60
|
|
|
60
|
|
110
|
my $self = shift; |
26
|
60
|
|
|
|
|
95
|
my $file = shift; |
27
|
60
|
|
|
|
|
187
|
my $attrfile = $self->_attribute_file($file); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# throws an exception if attrfile ain't YAML (or doesn't exist, etc.) |
30
|
60
|
|
|
|
|
261
|
my $data = LoadFile($attrfile); |
31
|
48
|
|
|
|
|
190475
|
return $data; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _save { |
35
|
26
|
|
|
26
|
|
61
|
my $self = shift; |
36
|
26
|
|
|
|
|
53
|
my $file = shift; |
37
|
26
|
|
|
|
|
102
|
my $data = shift; |
38
|
26
|
|
|
|
|
88
|
my $attrfile = $self->_attribute_file($file); |
39
|
|
|
|
|
|
|
|
40
|
26
|
100
|
|
|
|
135
|
if(!scalar keys %$data){ |
41
|
4
|
|
|
|
|
578
|
unlink $attrfile; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
22
|
|
|
|
|
105
|
DumpFile($attrfile, $data); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub list { |
49
|
9
|
|
|
9
|
1
|
426
|
my $self = shift; |
50
|
9
|
|
|
|
|
18
|
my $file = shift; |
51
|
9
|
|
|
|
|
21
|
my $data = {}; |
52
|
|
|
|
|
|
|
|
53
|
9
|
|
|
|
|
16
|
eval { |
54
|
9
|
|
|
|
|
26
|
$data = $self->_load($file); |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
9
|
|
|
|
|
6926
|
return keys %{$data}; |
|
9
|
|
|
|
|
59
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get { |
61
|
25
|
|
|
25
|
1
|
1068
|
my $self = shift; |
62
|
25
|
|
|
|
|
45
|
my $file = shift; |
63
|
25
|
|
|
|
|
44
|
my $attr = shift; |
64
|
25
|
|
|
|
|
77
|
my $data = $self->_load($file); |
65
|
|
|
|
|
|
|
|
66
|
25
|
|
|
|
|
192
|
return $data->{$attr}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub set { |
70
|
16
|
|
|
16
|
1
|
4313
|
my $self = shift; |
71
|
16
|
|
|
|
|
34
|
my $file = shift; |
72
|
16
|
|
|
|
|
35
|
my $key = shift; |
73
|
16
|
|
|
|
|
34
|
my $value = shift; |
74
|
|
|
|
|
|
|
|
75
|
16
|
|
|
|
|
39
|
my $data = {}; |
76
|
|
|
|
|
|
|
|
77
|
16
|
|
|
|
|
35
|
eval { |
78
|
16
|
|
|
|
|
57
|
$data = $self->_load($file); |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
16
|
|
|
|
|
30453
|
$data->{$key} = $value; |
82
|
16
|
|
|
|
|
78
|
$self->_save($file, $data); |
83
|
16
|
|
|
|
|
281154
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub unset { |
87
|
10
|
|
|
10
|
1
|
4107
|
my $self = shift; |
88
|
10
|
|
|
|
|
18
|
my $file = shift; |
89
|
10
|
|
|
|
|
18
|
my $key = shift; |
90
|
|
|
|
|
|
|
|
91
|
10
|
|
|
|
|
22
|
my $data = {}; |
92
|
10
|
|
|
|
|
17
|
eval { |
93
|
10
|
|
|
|
|
36
|
$data = $self->_load($file); |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
10
|
|
|
|
|
33
|
delete $data->{$key}; |
97
|
10
|
|
|
|
|
44
|
$self->_save($file, $data); |
98
|
10
|
|
|
|
|
12565
|
return 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _attribute_file { |
102
|
86
|
|
|
86
|
|
140
|
my $self = shift; |
103
|
86
|
|
|
|
|
141
|
my $file = shift; |
104
|
|
|
|
|
|
|
|
105
|
86
|
|
|
|
|
123
|
my $max = 10; |
106
|
86
|
|
66
|
|
|
722
|
while($max-- && -l $file){ |
107
|
17
|
|
|
|
|
1113
|
$file = readlink $file; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
86
|
|
|
|
|
5741
|
my ($volume,$dirs,$filename) = File::Spec->splitpath($file); |
111
|
86
|
|
|
|
|
3054
|
return File::Spec->catpath($volume, $dirs, ".$filename.attributes"); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |