line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: set ts=2 sts=2 sw=2 expandtab smarttab: |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This file is part of Dist-Metadata |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This software is copyright (c) 2011 by Randy Stauner. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
8
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
9
|
|
|
|
|
|
|
# |
10
|
2
|
|
|
2
|
|
970
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
11
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
153
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Dist::Metadata::Dir; |
14
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:RWSTAUNER'; |
15
|
|
|
|
|
|
|
# ABSTRACT: Enable Dist::Metadata for a directory |
16
|
|
|
|
|
|
|
$Dist::Metadata::Dir::VERSION = '0.926'; |
17
|
2
|
|
|
2
|
|
11
|
use Carp qw(croak carp); # core |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
163
|
|
18
|
2
|
|
|
2
|
|
12
|
use File::Find (); # core |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
19
|
2
|
|
|
2
|
|
9
|
use Path::Class 0.24 (); |
|
2
|
|
|
|
|
71
|
|
|
2
|
|
|
|
|
52
|
|
20
|
2
|
|
|
2
|
|
11
|
use parent 'Dist::Metadata::Dist'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
push(@Dist::Metadata::CARP_NOT, __PACKAGE__); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
13
|
|
|
13
|
1
|
2001
|
my $class = shift; |
27
|
13
|
|
|
|
|
85
|
my $self = $class->SUPER::new(@_); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# fix up dir (for example chop trailing slash if present) |
30
|
12
|
|
|
|
|
67
|
$self->{dir} = $self->path_class_dir->new($self->{dir})->stringify; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# TODO: croak if not -d $self->dir |
33
|
|
|
|
|
|
|
|
34
|
12
|
|
|
|
|
1091
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
14
|
1
|
56
|
sub required_attribute { 'dir' } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub determine_name_and_version { |
41
|
10
|
|
|
10
|
1
|
8329
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
# 'root' may be more accurate than 'dir' |
43
|
10
|
|
|
|
|
65
|
$self->SUPER::determine_name_and_version(); |
44
|
10
|
|
|
|
|
30
|
$self->set_name_and_version( $self->parse_name_and_version( $self->dir ) ); |
45
|
10
|
|
|
|
|
19
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub dir { |
50
|
12
|
|
|
12
|
1
|
4420
|
$_[0]->{dir}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# this shouldn't be called |
54
|
|
|
|
|
|
|
sub extract_into { |
55
|
1
|
|
|
1
|
1
|
157
|
croak q[A directory doesn't need to be extracted]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub file_content { |
60
|
6
|
|
|
6
|
1
|
8869
|
my ($self, $file) = @_; |
61
|
|
|
|
|
|
|
# This is a directory so file spec will always be native |
62
|
6
|
|
|
|
|
37
|
my $path = $self->path_class_file |
63
|
|
|
|
|
|
|
->new( $self->{dir}, $self->full_path($file) )->stringify; |
64
|
|
|
|
|
|
|
|
65
|
6
|
100
|
|
|
|
6954
|
open(my $fh, '<', $path) |
66
|
|
|
|
|
|
|
or croak "Failed to open file '$path': $!"; |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
10
|
return do { local $/; <$fh> }; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
236
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub find_files { |
73
|
13
|
|
|
13
|
1
|
1947
|
my ($self) = @_; |
74
|
|
|
|
|
|
|
|
75
|
13
|
|
|
|
|
24
|
my $dir = $self->{dir}; |
76
|
13
|
|
|
|
|
20
|
my @files; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
File::Find::find( |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
wanted => sub { |
81
|
125
|
100
|
|
125
|
|
14978
|
push @files, $self->path_class_file->new($_)->relative($dir)->stringify |
82
|
|
|
|
|
|
|
if -f $_; |
83
|
|
|
|
|
|
|
}, |
84
|
13
|
|
|
|
|
1483
|
no_chdir => 1 |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
$dir |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
13
|
|
|
|
|
3357
|
return @files; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub physical_directory { |
94
|
11
|
|
|
11
|
1
|
3742
|
my ($self, @files) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# TODO: return absolute_path? |
97
|
11
|
|
|
|
|
32
|
my @parts = $self->{dir}; |
98
|
|
|
|
|
|
|
# go into root dir if there is one |
99
|
11
|
100
|
|
|
|
61
|
push @parts, $self->root |
100
|
|
|
|
|
|
|
if $self->root; |
101
|
|
|
|
|
|
|
|
102
|
11
|
|
|
|
|
44
|
my $dir = $self->path_class_dir->new(@parts)->absolute; |
103
|
|
|
|
|
|
|
|
104
|
11
|
100
|
|
|
|
1717
|
return $dir->stringify unless wantarray; |
105
|
|
|
|
|
|
|
|
106
|
21
|
|
|
|
|
1078
|
return map { $_->stringify } |
|
12
|
|
|
|
|
380
|
|
107
|
9
|
|
|
|
|
22
|
($dir, map { $dir->file( $_ ) } @files); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |