Rolify Koral::Corpus

Change-Id: I1e566d4b59aee28168481734cf3343516f87a3e5
diff --git a/lib/Krawfish/Koral/Corpus.pm b/lib/Krawfish/Koral/Corpus.pm
index d2fa10d..e34234a 100644
--- a/lib/Krawfish/Koral/Corpus.pm
+++ b/lib/Krawfish/Koral/Corpus.pm
@@ -1,21 +1,43 @@
 package Krawfish::Koral::Corpus;
-use Role::Tiny::With;
-with 'Krawfish::Koral::Report';
-# TODO: Use the same parent as Koral::Query
+use Role::Tiny;
 use Krawfish::Koral::Corpus::Builder;
 use Krawfish::Log;
 use strict;
 use warnings;
 
+# TODO: Use the same role as Koral::Query
+
+# TODO: Add this everywhere
+with 'Krawfish::Koral::Report';
+
+requires qw/normalize
+            optimize
+            identify
+            type
+            operands
+            operand
+            finalize
+            has_classes
+            remove_classes
+            is_negative
+            is_anywhere
+            is_nowhere
+            is_null
+            is_leaf
+            from_koral
+            to_koral_fragment
+            to_string
+            to_neutral/;
+
 use constant DEBUG => 0;
 
 # Base object for virtual corpus queries
 
 # Constructor
-sub new {
-  my $class = shift;
-  bless {}, $class;
-};
+#sub new {
+#  my $class = shift;
+#  bless {}, $class;
+#};
 
 #########################################
 # Query Planning methods and attributes #
@@ -59,12 +81,6 @@
 };
 
 
-# Optimize for an index
-sub optimize {
-  warn 'override';
-};
-
-
 # Normalize to be on the root
 sub finalize {
   my $self = shift;
@@ -198,28 +214,6 @@
 };
 
 
-#############################
-# Query Application methods #
-#############################
-
-# Deserialize
-sub from_koral {
-  warn 'override';
-};
-
-
-# serialize
-sub to_koral_fragment {
-  warn 'override';
-};
-
-
-# Stringification
-sub to_string {
-  warn 'override';
-};
-
-
 # Serialize to neutral string
 sub to_neutral {
   $_[0]->to_string;
diff --git a/lib/Krawfish/Koral/Corpus/AndNot.pm b/lib/Krawfish/Koral/Corpus/AndNot.pm
index a62e150..3ecea8c 100644
--- a/lib/Krawfish/Koral/Corpus/AndNot.pm
+++ b/lib/Krawfish/Koral/Corpus/AndNot.pm
@@ -1,10 +1,12 @@
 package Krawfish::Koral::Corpus::AndNot;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Corpus::AndNot;
 use Krawfish::Log;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 use constant DEBUG => 0;
 
 # Construct AndNot query based on a positive and a negative operand
@@ -91,6 +93,10 @@
 };
 
 
+sub from_koral {
+  ...
+};
+
 # Stringification
 sub to_string {
   my $self = shift;
diff --git a/lib/Krawfish/Koral/Corpus/Anywhere.pm b/lib/Krawfish/Koral/Corpus/Anywhere.pm
index 4cf3444..3e0a02c 100644
--- a/lib/Krawfish/Koral/Corpus/Anywhere.pm
+++ b/lib/Krawfish/Koral/Corpus/Anywhere.pm
@@ -1,9 +1,11 @@
 package Krawfish::Koral::Corpus::Anywhere;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Corpus::Anywhere;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 # This matches all live documents!
 
 sub new {
@@ -50,4 +52,9 @@
   };
 };
 
+
+sub from_koral {
+  ...
+};
+
 1;
diff --git a/lib/Krawfish/Koral/Corpus/Cache.pm b/lib/Krawfish/Koral/Corpus/Cache.pm
index f5cc6d7..1e2250f 100644
--- a/lib/Krawfish/Koral/Corpus/Cache.pm
+++ b/lib/Krawfish/Koral/Corpus/Cache.pm
@@ -1,9 +1,11 @@
 package Krawfish::Koral::Corpus::Cache;
-use parent 'Krawfish::Koral::Corpus';
 use Krawfish::Corpus::Cache;
+use Role::Tiny::With;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 use constant DEBUG => 0;
 
 sub new {
@@ -44,5 +46,8 @@
   return $_[0]->operand->to_string;
 };
 
+sub from_koral {
+  ...
+};
 
 1;
diff --git a/lib/Krawfish/Koral/Corpus/Class.pm b/lib/Krawfish/Koral/Corpus/Class.pm
index 5ca27c0..2daaf11 100644
--- a/lib/Krawfish/Koral/Corpus/Class.pm
+++ b/lib/Krawfish/Koral/Corpus/Class.pm
@@ -1,11 +1,13 @@
 package Krawfish::Koral::Corpus::Class;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Corpus::Class;
 use Krawfish::Log;
 use strict;
 use warnings;
 use constant DEBUG => 0;
 
+with 'Krawfish::Koral::Corpus';
+
 
 sub new {
   my $class = shift;
@@ -76,6 +78,10 @@
   };
 };
 
+sub from_koral {
+  ...
+};
+
 
 sub to_string {
   my $self = shift;
diff --git a/lib/Krawfish/Koral/Corpus/Field.pm b/lib/Krawfish/Koral/Corpus/Field.pm
index 93e6be8..3d522bf 100644
--- a/lib/Krawfish/Koral/Corpus/Field.pm
+++ b/lib/Krawfish/Koral/Corpus/Field.pm
@@ -1,10 +1,12 @@
 package Krawfish::Koral::Corpus::Field;
-use parent 'Krawfish::Koral::Corpus';
 use Krawfish::Koral::Corpus::FieldID;
 use Krawfish::Util::Constants ':PREFIX';
+use Role::Tiny::With;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 use constant DEBUG => 0;
 
 # TODO:
@@ -273,6 +275,10 @@
 };
 
 
+sub from_koral {
+  ...
+};
+
 sub to_neutral {
   $_[0]->to_term;
 };
diff --git a/lib/Krawfish/Koral/Corpus/FieldGroup.pm b/lib/Krawfish/Koral/Corpus/FieldGroup.pm
index 88e2744..fd12bdb 100644
--- a/lib/Krawfish/Koral/Corpus/FieldGroup.pm
+++ b/lib/Krawfish/Koral/Corpus/FieldGroup.pm
@@ -1,16 +1,16 @@
 package Krawfish::Koral::Corpus::FieldGroup;
-use parent ('Krawfish::Koral::Util::Boolean', 'Krawfish::Koral::Corpus');
+use Role::Tiny::With;
 use Krawfish::Log;
 use Krawfish::Koral::Corpus::AndNot;
 use Krawfish::Koral::Corpus::Anywhere;
-
 use Krawfish::Corpus::Or;
-# use Krawfish::Corpus::OrWithFlags;
 use Krawfish::Corpus::And;
-# use Krawfish::Corpus::AndWithFlags;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Util::Boolean';
+with 'Krawfish::Koral::Corpus';
+
 # TODO:
 #   Preparation should be:
 #   -> normalize()
@@ -126,6 +126,11 @@
 };
 
 
+sub from_koral {
+  ...
+};
+
+
 1;
 
 
diff --git a/lib/Krawfish/Koral/Corpus/FieldID.pm b/lib/Krawfish/Koral/Corpus/FieldID.pm
index 6461014..ed95a66 100644
--- a/lib/Krawfish/Koral/Corpus/FieldID.pm
+++ b/lib/Krawfish/Koral/Corpus/FieldID.pm
@@ -1,9 +1,11 @@
 package Krawfish::Koral::Corpus::FieldID;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Corpus::FieldID;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 use constant DEBUG => 0;
 
 # TODO:
@@ -66,6 +68,11 @@
 };
 
 
+sub from_koral {
+  ...
+};
+
+
 sub to_koral_fragment {
   ...
 };
diff --git a/lib/Krawfish/Koral/Corpus/Nowhere.pm b/lib/Krawfish/Koral/Corpus/Nowhere.pm
index 5ca2f70..93c319c 100644
--- a/lib/Krawfish/Koral/Corpus/Nowhere.pm
+++ b/lib/Krawfish/Koral/Corpus/Nowhere.pm
@@ -1,9 +1,11 @@
 package Krawfish::Koral::Corpus::Nowhere;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Query::Nowhere;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 sub new {
   my $class = shift;
   bless {
@@ -41,4 +43,12 @@
   Krawfish::Query::Nowhere->new;
 };
 
+sub from_koral {
+  ...
+};
+
+sub to_koral_fragment {
+  ...
+};
+
 1;
diff --git a/lib/Krawfish/Koral/Corpus/Span.pm b/lib/Krawfish/Koral/Corpus/Span.pm
index 008392c..53dbb46 100644
--- a/lib/Krawfish/Koral/Corpus/Span.pm
+++ b/lib/Krawfish/Koral/Corpus/Span.pm
@@ -1,5 +1,5 @@
 package Krawfish::Koral::Corpus::Span;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use Krawfish::Util::Constants ':PREFIX';
 use Krawfish::Query::Nowhere;
 use Krawfish::Corpus::Span;
@@ -7,6 +7,8 @@
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 use constant DEBUG => 0;
 
 sub new {
@@ -159,6 +161,10 @@
 };
 
 
+sub from_koral {
+  ...
+};
+
 1;
 
 __END__
diff --git a/lib/Krawfish/Koral/Corpus/Static.pm b/lib/Krawfish/Koral/Corpus/Static.pm
index b0cbab9..de7a944 100644
--- a/lib/Krawfish/Koral/Corpus/Static.pm
+++ b/lib/Krawfish/Koral/Corpus/Static.pm
@@ -1,8 +1,10 @@
 package Krawfish::Koral::Corpus::Static;
-use parent 'Krawfish::Koral::Corpus';
+use Role::Tiny::With;
 use strict;
 use warnings;
 
+with 'Krawfish::Koral::Corpus';
+
 # Accepts an identifier to a static virtual corpus query
 # (e.g. a list of text/Siglen), represented as a normalized
 # KoralQuery file on disc.
diff --git a/lib/Krawfish/Koral/Query.pm b/lib/Krawfish/Koral/Query.pm
index e53edc5..8e406db 100644
--- a/lib/Krawfish/Koral/Query.pm
+++ b/lib/Krawfish/Koral/Query.pm
@@ -1,6 +1,5 @@
 package Krawfish::Koral::Query;
-use Role::Tiny::With;
-with 'Krawfish::Koral::Report';
+use Role::Tiny;
 # TODO: Use the same parent as Koral::Corpus
 use Krawfish::Koral::Query::Builder;
 use Krawfish::Koral::Query::Importer;
@@ -9,6 +8,8 @@
 use warnings;
 use strict;
 
+with 'Krawfish::Koral::Report';
+
 # Base class for span queries
 
 # TODO:
diff --git a/lib/Krawfish/Koral/Util/Boolean.pm b/lib/Krawfish/Koral/Util/Boolean.pm
index ae50e41..f5dba0e 100644
--- a/lib/Krawfish/Koral/Util/Boolean.pm
+++ b/lib/Krawfish/Koral/Util/Boolean.pm
@@ -1,4 +1,5 @@
 package Krawfish::Koral::Util::Boolean;
+use Role::Tiny;
 use Krawfish::Log;
 use List::MoreUtils qw!uniq!;
 use strict;
@@ -13,6 +14,9 @@
 
 use constant DEBUG => 0;
 
+requires qw/bool_and_query
+            bool_or_query/;
+
 # TODO:
 #   Introduce a ->complex attribute to all queries,
 #   to guarantee that simple operands are grouped together
diff --git a/t/koral/compile/node.t b/t/koral/compile/node.t
index 990af86..ddfb384 100644
--- a/t/koral/compile/node.t
+++ b/t/koral/compile/node.t
@@ -46,7 +46,5 @@
 
 diag 'Test normalization with nodes';
 
-diag 'Optimize segments in optimize() method';
-
 done_testing;
 __END__