Commits

Shlomi Fish  committed fd7e094

Add the clone method.

  • Participants
  • Parent commits e83dd54

Comments (0)

Files changed (2)

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

     return;
 }
 
+=head2 my $clone = $module->clone()
+
+Duplicates the object.
+
+=cut
+
+sub clone
+{
+    my $self = shift;
+
+    return ref($self)->_new({_components => $self->get_components_list() } );
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, L<http://www.shlomifish.org/> .

File Module-Format/Module-Format/t/module.t

 use strict;
 use warnings;
 
-use Test::More tests => 23;
+use Test::More tests => 31;
 
 use Module::Format::Module;
 
         "Format as dash is sane.",
     );
 }
+
+{
+    my $orig_module = Module::Format::Module->from(
+        {
+            format => 'colon',
+            value => 'XML::Grammar::Fiction',
+        }
+    );
+
+    # TEST
+    ok ($orig_module, '$orig_module is defined');
+
+    my $clone = $orig_module->clone();
+
+    # TEST
+    ok ($clone, '$clone is defined');
+
+    # TEST
+    is_deeply(
+        $clone->get_components_list(),
+        [qw(XML Grammar Fiction)],
+        "get_components_list() is sane.",
+    );
+
+    # TEST
+    is ($clone->format_as('colon'), 'XML::Grammar::Fiction',
+        "Format as colon is sane."
+    );
+
+    # TEST
+    is ($clone->format_as('dash'), 'XML-Grammar-Fiction',
+        "Format as dash is sane.",
+    );
+
+    # TEST
+    is ($clone->format_as('unix'), 'XML/Grammar/Fiction.pm',
+        "Format as unix is sane.",
+    );
+
+    # TEST
+    is ($clone->format_as('rpm_dash'), 'perl-XML-Grammar-Fiction',
+        "Format as rpm_dash is sane.",
+    );
+
+    # TEST
+    is ($clone->format_as('rpm_colon'), 'perl(XML::Grammar::Fiction)',
+        "Format as rpm_colon is sane.",
+    );
+
+}