Skip to content

Commit

Permalink
add clone and add_requirements methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Feb 22, 2010
1 parent a848600 commit 42492ea
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/Version/Requirements.pm
Expand Up @@ -121,6 +121,27 @@ BEGIN {
}
}

sub add_requirements {
my ($self, $req) = @_;

for my $module ($req->__modules) {
my $modifiers = $req->__entry_for($module)->as_modifiers;
for my $modifier (@$modifiers) {
my ($method, @args) = @$modifier;
$self->$method($module => @args);
};
}

return $self;
}

sub clone {
my ($self) = @_;
my $new = (ref $self)->new;

return $new->add_requirements($self);
}

sub __modules { keys %{ $_[ 0 ] } }
sub __entry_for { $_[0]{ $_[1] } }

Expand Down Expand Up @@ -166,6 +187,8 @@ sub as_string_hash {
return \%hash;
}

##############################################################

{
package
Version::Requirements::_Spec::Exact;
Expand All @@ -175,6 +198,8 @@ sub as_string_hash {

sub as_string { return "== $_[0]{version}" }

sub as_modifiers { return [ [ exact_version => $_[0]{version} ] ] }

sub with_exact_version {
my ($self, $version) = @_;

Expand Down Expand Up @@ -202,12 +227,23 @@ sub as_string_hash {
}
}

##############################################################

{
package
Version::Requirements::_Spec::Range;

sub _self { ref($_[0]) ? $_[0] : (bless { } => $_[0]) }

sub as_modifiers {
my ($self) = @_;
my @mods;
push @mods, [ add_minimum => $self->{minimum} ] if exists $self->{minimum};
push @mods, [ add_maximum => $self->{maximum} ] if exists $self->{maximum};
push @mods, map {; [ add_exclusion => $_ ] } @{$self->{exclusions} || []};
return \@mods;
}

sub as_string {
my ($self) = @_;

Expand Down

0 comments on commit 42492ea

Please sign in to comment.