Commits

Shlomi Fish  committed 34bc6e0

Add the beginning of ModuleList.

Implemented the ->new constructor.

  • Participants
  • Parent commits 8039fbf

Comments (0)

Files changed (3)

File Module-Format/Module-Format/MANIFEST

 README
 t/00-load.t
 t/module.t
+t/module-list.t
 t/pod-coverage.t
 t/pod.t
 Makefile.PL

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

         {
             modules =>
             [
-                Module::Format::Module->from_guess('XML::RSS'),
-                Module::Format::Module->from_guess('Data-Dumper'),
+                Module::Format::Module->from_guess({ value => 'XML::RSS'}),
+                Module::Format::Module->from_guess({ value => 'Data-Dumper'}),
             ],
         }
     );
         },
     )
 
+=head1 FUNCTIONS
+
 =cut
 
 use Module::Format::Module;
 
+=head2 my $list = Module::Format::ModuleList->new({ modules => \@list})
+
+The generic constructor. Initialises a new module list from a @list which
+must be an array of L<Module::Format::Module> modules.
+
+=cut
+
+sub new
+{
+    my $class = shift;
+    my $self = bless {}, $class;
+    $self->_init(@_);
+    return $self;
+}
+
+sub _modules
+{
+    my $self = shift;
+
+    if (@_) {
+        $self->{_modules} = shift;
+    }
+
+    return $self->{_modules};
+}
+
+sub _add_module
+{
+    my ($self, $module) = @_;
+
+    if (not $module->isa('Module::Format::Module'))
+    {
+        die "Module is " . ref($module) . " instead of Module::Format::Module.";
+    }
+
+    push @{$self->_modules()}, $module;
+
+    return;
+}
+
+sub _init
+{
+    my ($self, $args) = @_;
+
+    $self->_modules([]);
+
+    foreach my $module (@{$args->{modules}})
+    {
+        $self->_add_module($module);
+    }
+
+    return;
+}
+
 =head1 AUTHOR
 
 Shlomi Fish, L<http://www.shlomifish.org/>

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

+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use Module::Format::ModuleList;
+
+{
+    my $list = Module::Format::ModuleList->new(
+        {
+            modules =>
+            [
+                Module::Format::Module->from_guess({value => 'XML::RSS'}),
+                Module::Format::Module->from_guess({value => 'Data-Dumper'}),
+            ],
+        }
+    );
+
+    # TEST
+    ok ($list, "Module::Format::Module->new returns true.");
+}