Commits

Shlomi Fish  committed 8b06ed4

Add is_sane().

This checks that the components do not contain any funny characters.

  • Participants
  • Parent commits 49ebe79

Comments (0)

Files changed (2)

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

 use warnings;
 use strict;
 
+use List::MoreUtils qw(all);
+
 =head1 NAME
 
 Module::Format::Module - encapsulates a single Perl module.
     );
 }
 
+=head2 my $bool = $module->is_sane();
+
+Returns a boolean depending on if the component of the module do not contain
+any funny character (only alphanumeric characters and underscore.).
+
+=cut
+
+sub is_sane
+{
+    my $self = shift;
+
+    return all { m{\A\w+\z} } @{$self->_components()};
+}
+
 =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 => 39;
+use Test::More tests => 41;
 
 use Module::Format::Module;
 
         "Format as rpm_colon is sane.",
     );
 }
+
+{
+    my $module = Module::Format::Module->from_components(
+        {
+            components => [qw(XML Grammar Fiction)],
+        }
+    );
+
+    # TEST
+    ok (scalar($module->is_sane()), "Module is sane.");
+}
+
+{
+    my $module = Module::Format::Module->from_components(
+        {
+            components => ['XML', 'F@L',],
+        }
+    );
+
+    # TEST
+    ok (!scalar($module->is_sane()), "Module is not sane.");
+}
+
+