diff options
Diffstat (limited to 'Bugzilla/Version.pm')
-rw-r--r-- | Bugzilla/Version.pm | 130 |
1 files changed, 121 insertions, 9 deletions
diff --git a/Bugzilla/Version.pm b/Bugzilla/Version.pm index 7c341b654..4b332ff2b 100644 --- a/Bugzilla/Version.pm +++ b/Bugzilla/Version.pm @@ -5,13 +5,16 @@ # This Source Code Form is "Incompatible With Secondary Licenses", as # defined by the Mozilla Public License, v. 2.0. +package Bugzilla::Version; + +use 5.10.1; use strict; +use warnings; -package Bugzilla::Version; +use parent qw(Bugzilla::Object Exporter); -use base qw(Bugzilla::Object); +@Bugzilla::Version::EXPORT = qw(vers_cmp); -use Bugzilla::Install::Util qw(vers_cmp); use Bugzilla::Util; use Bugzilla::Error; @@ -172,8 +175,8 @@ sub product { # Validators ################################ -sub set_name { $_[0]->set('value', $_[1]); } -sub set_is_active { $_[0]->set('isactive', $_[1]); } +sub set_value { $_[0]->set('value', $_[1]); } +sub set_isactive { $_[0]->set('isactive', $_[1]); } sub _check_value { my ($invocant, $name, undef, $params) = @_; @@ -199,6 +202,53 @@ sub _check_product { return Bugzilla->user->check_can_admin_product($product->name); } +############################### +##### Functions #### +############################### + +# This is taken straight from Sort::Versions 1.5, which is not included +# with perl by default. +sub vers_cmp { + my ($a, $b) = @_; + + # Remove leading zeroes - Bug 344661 + $a =~ s/^0*(\d.+)/$1/; + $b =~ s/^0*(\d.+)/$1/; + + my @A = ($a =~ /([-.]|\d+|[^-.\d]+)/g); + my @B = ($b =~ /([-.]|\d+|[^-.\d]+)/g); + + my ($A, $B); + while (@A and @B) { + $A = shift @A; + $B = shift @B; + if ($A eq '-' and $B eq '-') { + next; + } elsif ( $A eq '-' ) { + return -1; + } elsif ( $B eq '-') { + return 1; + } elsif ($A eq '.' and $B eq '.') { + next; + } elsif ( $A eq '.' ) { + return -1; + } elsif ( $B eq '.' ) { + return 1; + } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) { + if ($A =~ /^0/ || $B =~ /^0/) { + return $A cmp $B if $A cmp $B; + } else { + return $A <=> $B if $A <=> $B; + } + } else { + $A = uc $A; + $B = uc $B; + return $A cmp $B if $A cmp $B; + } + } + return @A <=> @B; +} + 1; __END__ @@ -222,7 +272,7 @@ Bugzilla::Version - Bugzilla product version class. my $version = Bugzilla::Version->create( { value => $name, product => $product_obj }); - $version->set_name($new_name); + $version->set_value($new_name); $version->update(); $version->remove_from_db; @@ -242,12 +292,74 @@ below. =item C<bug_count()> - Description: Returns the total of bugs that belong to the version. +=over + +=item B<Description> - Params: none. +Returns the total of bugs that belong to the version. - Returns: Integer with the number of bugs. +=item B<Params> + +none + +=item B<Returns> + +Integer with the number of bugs. + +=back + +=back + +=head1 FUNCTIONS + +=over + +=item C<vers_cmp($a, $b)> + +=over + +=item B<Description> + +This is a comparison function, like you would use in C<sort>, except that +it compares two version numbers. So, for example, 2.10 would be greater +than 2.2. + +It's based on versioncmp from L<Sort::Versions>, with some Bugzilla-specific +fixes. + +=item B<Params> + +C<$a> and C<$b> - The versions you want to compare. + +=item B<Returns> + +C<-1> if C<$a> is less than C<$b>, C<0> if they are equal, or C<1> if C<$a> +is greater than C<$b>. + +=back =back =cut + +=head1 B<Methods in need of POD> + +=over + +=item DEFAULT_VERSION + +=item set_isactive + +=item set_value + +=item product_id + +=item is_active + +=item remove_from_db + +=item product + +=item update + +=back |