line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Attributes; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# please see POD after __END__ |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
145128
|
use warnings; |
|
6
|
|
|
|
|
34
|
|
|
6
|
|
|
|
|
225
|
|
6
|
6
|
|
|
6
|
|
33
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
196
|
|
7
|
6
|
|
|
6
|
|
35
|
use Carp; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
634
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# modules that we require |
11
|
6
|
|
|
|
|
51
|
use Module::Pluggable ( search_path => 'File::Attributes', |
12
|
6
|
|
|
6
|
|
6295
|
instantiate => 'new' ); |
|
6
|
|
|
|
|
100351
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# exporting business |
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
17
|
|
|
|
|
|
|
our @EXPORT = (); |
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw(set_attribute set_attributes |
19
|
|
|
|
|
|
|
get_attribute get_attributes |
20
|
|
|
|
|
|
|
unset_attribute unset_attributes |
21
|
|
|
|
|
|
|
list_attributes); |
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# internal variables |
25
|
|
|
|
|
|
|
my @modules; # the modules to call, in order |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _foreach_plugin(@&){ |
28
|
29
|
|
|
29
|
|
97
|
my @args = @_; |
29
|
29
|
|
|
|
|
48
|
my $file = $args[0]; |
30
|
29
|
|
|
|
|
71
|
my $code = pop @args; |
31
|
|
|
|
|
|
|
|
32
|
29
|
100
|
|
|
|
432
|
croak "$file does not exist" if !-e $file; |
33
|
|
|
|
|
|
|
|
34
|
28
|
|
|
|
|
2121
|
foreach my $plugin (@modules){ |
35
|
28
|
50
|
|
|
|
129
|
next if !$plugin->applicable($file); |
36
|
28
|
|
|
|
|
89
|
my @result = $code->($plugin, @args); |
37
|
28
|
100
|
|
|
|
401
|
if(@result){ |
38
|
18
|
50
|
|
|
|
55
|
return @result if wantarray; |
39
|
18
|
|
|
|
|
203
|
return $result[0]; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub set_attribute { |
45
|
7
|
|
|
7
|
1
|
11
|
_foreach_plugin @_, sub { my $p = shift; $p->set(@_) }; |
|
7
|
|
|
7
|
|
34
|
|
|
7
|
|
|
|
|
465498
|
|
46
|
7
|
|
|
|
|
55
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_attributes { |
50
|
1
|
|
|
1
|
1
|
918
|
my $file = shift; |
51
|
1
|
|
|
|
|
3
|
my $first = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# if someone passes a hashref instead, handle that nicely |
54
|
1
|
|
|
|
|
3
|
my %attributes; |
55
|
1
|
50
|
|
|
|
5
|
if(ref $first){ |
56
|
0
|
|
|
|
|
0
|
%attributes = %{$first}; |
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
1
|
|
|
|
|
7
|
%attributes = ($first, @_); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
5
|
foreach my $key (keys %attributes){ |
63
|
3
|
|
|
|
|
10
|
set_attribute($file, $key, $attributes{$key}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_attribute { |
68
|
11
|
|
|
11
|
1
|
17
|
return _foreach_plugin @_, sub { my $p = shift; $p->get(@_) }; |
|
11
|
|
|
11
|
|
47
|
|
|
11
|
|
|
|
|
82
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_attributes { |
72
|
3
|
|
|
3
|
1
|
763
|
my $file = shift; |
73
|
3
|
|
|
|
|
10
|
my @attributes = list_attributes($file); |
74
|
3
|
|
|
|
|
6
|
my %result; |
75
|
3
|
|
|
|
|
8
|
foreach my $attribute (@attributes){ |
76
|
5
|
|
|
|
|
15
|
$result{$attribute} = get_attribute($file, $attribute); |
77
|
|
|
|
|
|
|
} |
78
|
3
|
|
|
|
|
109
|
return %result; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub unset_attribute { |
82
|
|
|
|
|
|
|
_foreach_plugin @_, |
83
|
5
|
|
|
5
|
|
10
|
sub { my $p = shift; |
84
|
5
|
|
|
|
|
24
|
$p->unset(@_); |
85
|
5
|
|
|
|
|
187
|
return; # force unset on all plugins |
86
|
5
|
|
|
5
|
1
|
1350
|
}; |
87
|
5
|
|
|
|
|
35
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub unset_attributes { |
91
|
1
|
|
|
1
|
1
|
2715
|
my $file = shift; |
92
|
1
|
|
|
|
|
5
|
my @attributes = @_; |
93
|
1
|
|
|
|
|
3
|
foreach my $attribute (@attributes){ |
94
|
3
|
|
|
|
|
11
|
unset_attribute($file, $attribute); |
95
|
|
|
|
|
|
|
} |
96
|
1
|
|
|
|
|
5
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub list_attributes { |
100
|
6
|
|
|
6
|
1
|
124693
|
my @result; |
101
|
|
|
|
|
|
|
_foreach_plugin @_, |
102
|
|
|
|
|
|
|
sub { |
103
|
5
|
|
|
5
|
|
11
|
my $p = shift; |
104
|
5
|
|
|
|
|
29
|
push @result, $p->list(@_); |
105
|
5
|
|
|
|
|
20
|
return; # force examination of all plugins |
106
|
6
|
|
|
|
|
46
|
}; |
107
|
5
|
|
|
|
|
24
|
my %result = map { $_ => 1 } @result; # filter out dupes |
|
7
|
|
|
|
|
27
|
|
108
|
5
|
|
|
|
|
27
|
return keys %result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _init { |
112
|
6
|
|
|
6
|
|
10
|
my $simple; |
113
|
6
|
|
|
|
|
22
|
foreach my $plugin (plugins()){ |
114
|
12
|
|
|
|
|
123
|
eval { |
115
|
12
|
100
|
66
|
|
|
142
|
push @modules, $plugin |
116
|
|
|
|
|
|
|
if $plugin->isa('File::Attributes::Base') && |
117
|
|
|
|
|
|
|
$plugin->priority > 0; |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# sort from highest priority to lowest |
122
|
6
|
|
|
|
|
174
|
@modules = reverse sort {$a->priority <=> $b->priority} @modules; |
|
0
|
|
|
|
|
0
|
|
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
110
|
return scalar @modules; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _modules { |
128
|
3
|
|
|
3
|
|
676402
|
return map {/(.+)=[A-Z]+/; $1;} @modules; |
|
3
|
|
|
|
|
53
|
|
|
3
|
|
|
|
|
20
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
return _init(); # returns true if the module can be used |
132
|
|
|
|
|
|
|
__END__ |