Enbld/Definition/Vim.pm untested

filter: Statementstmt 0.0% 0 / 104 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 145 SCAR 45.0
CC
9
Cov
0%
_search_major_version
20.0
set_patchfiles
12.0
_search_patchfiles
12.0
CRAP 90.0
1 package Enbld::Definition::Vim;
2  
3 use strict;
4 use warnings;
5  
6 use version;
7  
8 use parent qw/Enbld::Definition/;
9  
10 use List::Util qw/first max/;
11  
12 require Enbld::HTTP;
13  
14 sub initialize {
15 my $self = shift;
16  
17 $self->SUPER::initialize;
18  
19 $self->{defined}{ArchiveName} = 'vim';
20 $self->{defined}{WebSite} = 'http://www.vim.org';
21 $self->{defined}{VersionForm} = '7\.\d(?:\.\d{3,4})?';
22 $self->{defined}{Extension} = 'tar.bz2';
23 $self->{defined}{DownloadSite} = 'http://ftp.vim.org/pub/vim/unix/';
24  
25 $self->{defined}{AdditionalArgument} =
26 '--enable-multibyte --with-features=big';
27  
28 $self->{defined}{VersionList} = \&set_versionlist;
29  
30 $self->{defined}{Filename} = \&set_filename;
31 $self->{defined}{Version} = \&set_version;
32 $self->{defined}{PatchFiles} = \&set_patchfiles;
33  
34 $self->{defined}{TestAction} = 'test';
35  
36 return $self;
37 }
38  
39 sub set_filename {
40 my $attributes = shift;
41  
42 my $archive_name = $attributes->ArchiveName;
43 my $major = _search_major_version( $attributes );
44 my $extension = $attributes->Extension;
45
46 my $filename = $archive_name . '-' . $major . '.' . $extension;
47  
48 return $filename;
49 }
50  
51 sub set_version {
52 my $attributes = shift;
53  
54 my $major = _search_major_version( $attributes );
55 my $patchfiles = _search_patchfiles( $attributes, $major );
56  
57 return $major unless ( $patchfiles );
58  
59 return $patchfiles->[-1];
60 }
61  
62 sub set_patchfiles {
63 my $attributes = shift;
64  
65 my $major = _search_major_version( $attributes );
66 my $patchfiles = _search_patchfiles( $attributes, $major );
67  
68 return unless ( $patchfiles );
69  
70 my $url = 'http://ftp.vim.org/pub/vim/patches/';
71  
72 my $list;
73 foreach my $patch ( @{ $patchfiles } ) {
74 next if ( $attributes->VersionCondition ne 'latest' &&
75 version->declare( $attributes->VersionCondition ) <
76 version->declare( $patch ) );
77  
78 push @{ $list }, $url . $major . '/'. $patch;
79 }
80  
81 return $list;
82 }
83  
84 sub _search_major_version {
85 my $attributes = shift;
86  
87 my $html = Enbld::HTTP->get_html( $attributes->IndexSite );
88 my $list = $html->parse_version( '<a href="vim-7\.\d\.tar\.bz2">', '7\.\d');
89  
90 unless ( @{ $list } ) {
91 require Enbld::Error;
92 die( Enbld::Error->new( "Can't get version list." ));
93 }
94  
95 my @sorted = sort {
96 version->declare( $a ) cmp version->declare( $b )
97 } @{ $list };
98  
99 return $sorted[-1] if ( $attributes->VersionCondition eq 'latest' );
100  
101 my $major = substr( $attributes->VersionCondition, 0, 3 );
102  
103 return $major if ( grep { $major eq $_ } @{ $list } );
104  
105 require Enbld::Error;
106 die( Enbld::Error->new(
107 "Invalid Version Condition:$attributes->VersionCondition, ".
108 "please check install condition"
109 ));
110 }
111  
112 sub _search_patchfiles {
113 my $attributes = shift;
114 my $major = shift;
115  
116 my $url = 'http://ftp.vim.org/pub/vim/patches/';
117 my $html_list = Enbld::HTTP->get_html( $url );
118 my $dir_list = $html_list->parse_version( '<a href="7\.\d/">', $major );
119  
120 return unless ( $dir_list );
121  
122 my $html_patchfiles = Enbld::HTTP->get_html( $url . $major );
123 my $patchfiles = $html_patchfiles->parse_version(
124 '<a href="7\.\d\.\d{3,4}">',
125 $attributes->VersionForm
126 );
127  
128 return unless ( @{ $patchfiles } );
129  
130 my @sorted = sort {
131 version->declare( $a ) cmp version->declare( $b )
132 } @{ $patchfiles };
133  
134 return \@sorted;
135 }
136  
137 sub set_versionlist {
138 my $attributes = shift;
139  
140 my $versionlist;
141  
142 # search major version number
143 my $html = Enbld::HTTP->get_html( $attributes->IndexSite );
144 my $list = $html->parse_version( '<a href="vim-7\.\d\.tar\.bz2">', '7\.\d');
145  
146 push @{ $versionlist }, @{ $list };
147  
148 # search patch number
149 for my $ver ( @{ $list } ) {
150 my $patchlist = _search_patchfiles( $attributes, $ver );
151 push @{ $versionlist }, @{ $patchlist };
152 }
153  
154 return $versionlist;
155 }
156  
157 1;
158  
159 =pod
160  
161 =head1 NAME
162  
163 Enbld::Definition::Vim - definition module for Vim
164  
165 =head1 SEE ALSO
166  
167 L<Vim|http://www.vim.org>
168  
169 L<Enbld::Definition>
170  
171 =head1 COPYRIGHT
172  
173 copyright 2013- Magnolia C<< <magnolia.k@me.com> >>.
174  
175 =head1 LICENSE
176  
177 This is free software; you can redistribute it and/or modify it under
178 the same terms as the Perl 5 programming language system itself.
179  
180 =cut