Anonymous avatar Anonymous committed 0bd3c6b

Extract a common method.

Comments (0)

Files changed (1)

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/FromProto/Parser/XmlIterator.pm

     );
 }
 
+sub _generic_para_contents_assert
+{
+    my ($self, $predicate, $message, $contents) = @_;
+
+    if (List::MoreUtils::any { $predicate->($_) } @{$contents || []})
+    {
+        Carp::confess ($message);
+    }
+
+    return;
+}
 
 sub _assert_not_contains_saying
 {
     my ($self, $contents) = @_;
 
-    if (List::MoreUtils::any 
-        { ref($_) ne "" && $_->isa("XML::Grammar::Fiction::FromProto::Node::Saying") }
-        @{$contents || []}
-        )
-    {
-        Carp::confess (qq{Para contains a saying.});
-    }
-
-    return;
+    return $self->_generic_para_contents_assert(
+        sub { ref($_) ne "" && $_->isa("XML::Grammar::Fiction::FromProto::Node::Saying") },
+        qq{Para contains a saying.},
+        $contents
+    );
 }
 
 sub _assert_not_contains_undef
 {
     my ($self, $contents) = @_;
 
-    # This is an assert
-    if (List::MoreUtils::any 
-        { !defined($_) }
-        @{$contents || []}
-        )
-    {
-        Carp::confess (qq{Para contains an undef member.});
-    }
-
-    return;
+    return $self->_generic_para_contents_assert(
+        sub { !defined($_) },
+        qq{Para contains an undef member.},
+        $contents
+    );
 }
 
-
 sub _new_para
 {
     my ($self, $contents) = @_;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.