Commits

Shlomi Fish committed 677ed0f

Refactored into returning the components.

Comments (0)

Files changed (1)

Module-Format/Module-Format/lib/Module/Format/Module.pm

 
 =cut
 
-sub from
+sub _calc_components_from_string
 {
     my ($class, $args) = @_;
 
     my $format = $args->{format};
     my $value = $args->{value};
 
-    my @components;
-
     if ($format eq 'colon')
     {
-        @components = split(/::/, $value, -1);
+        return [split(/::/, $value, -1)];
     }
     elsif ($format eq 'dash')
     {
-        @components = split(/-/, $value, -1);
+        return [split(/-/, $value, -1)];
     }
     elsif ($format eq 'unix')
     {
             die "Cannot find a .pm suffix in the 'unix' format.";
         }
 
-        @components = split(m{/}, $value, -1);
+        return [split(m{/}, $value, -1)];
     }
     elsif ($format eq 'rpm_colon')
     {
         {
             die "Improper value for rpm_colon";
         }
-        return $class->from({format => 'colon', value => $1});
+
+        return $class->_calc_components_from_string(
+            {format => 'colon', value => $1}
+        );
     }
     elsif ($format eq 'rpm_dash')
     {
             die "rpm_dash value does not start with the 'perl-' prefix.";
         }
         
-        return $class->from({format => 'dash', value => $value});
+        return $class->_calc_components_from_string(
+            {format => 'dash', value => $value}
+        );
     }
     else
     {
         die "Unknown format '$format'!";
     }
+}
 
-    return $class->_new({_components => \@components});
+sub from
+{
+    my ($class, $args) = @_;
+
+    my $format = $args->{format};
+    my $value = $args->{value};
+
+    return $class->_new(
+        {
+            _components => $class->_calc_components_from_string($args)
+        }
+    );
 }
 
 =head2 my $array_ref = $module->get_components_list()