File: Version.pm

package info (click to toggle)
libmodule-cpants-analyse-perl 0.86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 448 kB
  • sloc: perl: 1,781; sh: 48; makefile: 10
file content (167 lines) | stat: -rw-r--r-- 3,701 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package Module::CPANTS::Kwalitee::Version;
use warnings;
use strict;
use File::Find;
use File::Spec::Functions qw(catdir catfile abs2rel splitdir);
use File::stat;
use File::Basename;

sub order { 100 }

##################################################################
# Analyse
##################################################################

my $match_version = qr/\$VERSION/;

sub analyse {
    my $class=shift;
    my $me=shift;
    my $distdir=$me->distdir;
    

    my %version_of;
    foreach my $module (@{$me->d->{modules}}) {
        my $version;
        if (open my $fh, '<', catfile($distdir, $module->{file})) {
            while (my $line = <$fh>) {
                if ($line =~ $match_version) {
                    $version = $line;  
                    last;
                }
            }
        }
        $version_of{$module->{file}} = $version;
    }

    $me->d->{versions} = \%version_of;

    return;
}



##################################################################
# Kwalitee Indicators
##################################################################

sub kwalitee_indicators {
  return [
    {
        name=>'has_version_in_each_file',
        error=>qq{This distribution has a .pm file without version number. (Using $match_version to match them)},
        remedy=>q{Add a version number to each .pm file.},
        is_experimental=>1,
        code=>sub {
            my $d=shift;
            #use Data::Dumper;
            #die Dumper $d->{versions};
            my $number_modules = scalar @{$d->{modules}};
            my $number_pm_with_version = scalar grep { defined $d->{versions}{$_} } keys %{ $d->{versions} };
            
            if ($number_modules == $number_pm_with_version) {
                return 1;
            }
            else {
                my @errors = map { $_ }
                    grep { ! defined $d->{versions}{$_} }
                    keys %{ $d->{versions} };
                $d->{error}{has_version_in_each_file} = \@errors;
                return 0;
            }
        },
    },
];
}


q{Favourite record of the moment:
  Fat Freddys Drop: Based on a true story};


__END__

=encoding UTF-8

=head1 NAME

Module::CPANTS::Kwalitee::Files - Check for various files

=head1 SYNOPSIS

Find various files and directories that should be part of every self-respecting distribution.

=head1 DESCRIPTION

=head2 Methods

=head3 order

Defines the order in which Kwalitee tests should be run.

Returns C<10>, as data generated by C<MCK::Files> is used by all other tests.

=head3 map_filenames

get db_filenames from real_filenames

=head3 analyse

C<MCK::Files> uses C<File::Find> to get a list of all files and dirs in a dist. It checks if certain crucial files are there, and does some other file-specific stuff.

=head3 get_files

The subroutine used by C<File::Find>. Unfortunantly, it depends on some global values.

=head3 kwalitee_indicators

Returns the Kwalitee Indicators datastructure.

=over

=item * extractable

=item * extracts_nicely

=item * has_readme

=item * has_manifest

=item * has_meta_yml

=item * has_buildtool

=item * has_changelog 

=item * no_symlinks

=item * has_tests

=item * has_tests_in_t_dir

=item * buildfile_not_executabel

=item * has_example (optional)

=item * no_generated_file

=item * has_version_in_each_file

=item * no_stdin_for_prompting

=back

=head1 SEE ALSO

L<Module::CPANTS::Analyse>

=head1 AUTHOR

L<Thomas Klausner|https://metacpan.org/author/domm>

=head1 COPYRIGHT AND LICENSE

Copyright © 2003–2006, 2009 L<Thomas Klausner|https://metacpan.org/author/domm>

You may use and distribute this module according to the same terms
that Perl is distributed under.