Lines 47-55
sub new {
Link Here
|
47 |
if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) { |
47 |
if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) { |
48 |
if ( $self->install() ) { |
48 |
if ( $self->install() ) { |
49 |
$self->store_data( { '__INSTALLED__' => 1 } ); |
49 |
$self->store_data( { '__INSTALLED__' => 1 } ); |
|
|
50 |
if ( my $version = $self->get_metadata->{version} ) { |
51 |
$self->store_data({ '__INSTALLED_VERSION__' => $version }); |
52 |
} |
50 |
} else { |
53 |
} else { |
51 |
warn "Plugin $class failed during installation!"; |
54 |
warn "Plugin $class failed during installation!"; |
52 |
} |
55 |
} |
|
|
56 |
} elsif ( $self->can('upgrade') && $self->get_metadata->{version} && $self->retrieve_data('__INSTALLED_VERSION__') ) { |
57 |
if ( $self->_version_compare( $self->get_metadata->{version}, $self->retrieve_data('__INSTALLED_VERSION__') ) > 0 ) { |
58 |
unless ( $self->upgrade() ) { |
59 |
warn "Plugin $class failed during upgrade!"; |
60 |
} |
61 |
} |
53 |
} |
62 |
} |
54 |
|
63 |
|
55 |
return $self; |
64 |
return $self; |
Lines 218-223
sub output {
Link Here
|
218 |
output_with_http_headers( $self->{cgi}, undef, $data, $content_type, $status, $extra_options ); |
227 |
output_with_http_headers( $self->{cgi}, undef, $data, $content_type, $status, $extra_options ); |
219 |
} |
228 |
} |
220 |
|
229 |
|
|
|
230 |
=head2 _version_compare |
231 |
|
232 |
Utility method to compare two version numbers |
233 |
|
234 |
if ( $self->version_compare( '2.6.26', '2.6.0' ) == 1 ) { |
235 |
print "2.6.26 is greater than 2.6.0\n"; |
236 |
} |
237 |
|
238 |
=cut |
239 |
|
240 |
sub _version_compare { |
241 |
my $ver1 = shift || 0; |
242 |
my $ver2 = shift || 0; |
243 |
my @v1 = split /[.+:~-]/, $ver1; |
244 |
my @v2 = split /[.+:~-]/, $ver2; |
245 |
|
246 |
for ( my $i = 0 ; $i < max( scalar(@v1), scalar(@v2) ) ; $i++ ) { |
247 |
|
248 |
# Add missing version parts if one string is shorter than the other |
249 |
# i.e. 0 should be lt 0.2.1 and not equal, so we append .0 |
250 |
# -> 0.0.0 <=> 0.2.1 -> -1 |
251 |
push( @v1, 0 ) unless defined( $v1[$i] ); |
252 |
push( @v2, 0 ) unless defined( $v2[$i] ); |
253 |
if ( int( $v1[$i] ) > int( $v2[$i] ) ) { |
254 |
return 1; |
255 |
} |
256 |
elsif ( int( $v1[$i] ) < int( $v2[$i] ) ) { |
257 |
return -1; |
258 |
} |
259 |
} |
260 |
return 0; |
261 |
} |
262 |
|
221 |
1; |
263 |
1; |
222 |
__END__ |
264 |
__END__ |
223 |
|
265 |
|