From: tla Date: Tue, 21 Jan 2014 15:04:13 +0000 (+0100) Subject: move custom datatypes to their own package; add ternary is_significant to relationshi... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27e161befcbed6210f8d8a37d1d5d3363fe70bd8;p=scpubgit%2Fstemmatology.git move custom datatypes to their own package; add ternary is_significant to relationships. Needed for tla/stemmaweb#33 --- diff --git a/base/lib/Text/Tradition/Collation/Reading.pm b/base/lib/Text/Tradition/Collation/Reading.pm index a482b60..6852a34 100644 --- a/base/lib/Text/Tradition/Collation/Reading.pm +++ b/base/lib/Text/Tradition/Collation/Reading.pm @@ -2,18 +2,11 @@ package Text::Tradition::Collation::Reading; use Moose; use Moose::Util qw/ does_role apply_all_roles /; -use Moose::Util::TypeConstraints; +use Text::Tradition::Datatypes; use Text::Tradition::Error; use XML::Easy::Syntax qw( $xml10_name_rx $xml10_namestartchar_rx ); use overload '""' => \&_stringify, 'fallback' => 1; -subtype 'ReadingID', - as 'Str', - where { $_ =~ /\A$xml10_name_rx\z/ }, - message { 'Reading ID must be a valid XML attribute string' }; - -no Moose::Util::TypeConstraints; - # Enable plugin(s) if available eval { with 'Text::Tradition::Morphology'; }; # Morphology package is not on CPAN, so don't warn of its absence diff --git a/base/lib/Text/Tradition/Collation/Relationship.pm b/base/lib/Text/Tradition/Collation/Relationship.pm index 4141f44..3b27c76 100644 --- a/base/lib/Text/Tradition/Collation/Relationship.pm +++ b/base/lib/Text/Tradition/Collation/Relationship.pm @@ -1,11 +1,7 @@ package Text::Tradition::Collation::Relationship; use Moose; -use Moose::Util::TypeConstraints; - -enum 'RelationshipScope' => [ qw( local document global ) ]; - -no Moose::Util::TypeConstraints; +use Text::Tradition::Datatypes; =head1 NAME @@ -56,6 +52,10 @@ and >1 (yes). =item * non_independent - (Optional) True if the variant is unlikely to have occurred independently in unrelated witnesses. +=item * is_significant - (Optional) Indicates whether, in the opinion of the scholar, +the variation in question is stemmatically significant. Possible values are 'yes', +'maybe', and 'no'. + =back =head1 ACCESSORS @@ -74,6 +74,8 @@ occurred independently in unrelated witnesses. =head2 non_independent +=head2 is_significant + See the option descriptions above. =cut @@ -135,6 +137,12 @@ has 'non_independent' => ( isa => 'Bool', ); +has 'is_significant' => ( + is => 'ro', + isa => 'Ternary', + default => 'no', + ); + around 'alters_meaning' => sub { my $orig = shift; my $self = shift; diff --git a/base/lib/Text/Tradition/Datatypes.pm b/base/lib/Text/Tradition/Datatypes.pm new file mode 100644 index 0000000..dc7d414 --- /dev/null +++ b/base/lib/Text/Tradition/Datatypes.pm @@ -0,0 +1,25 @@ +package Text::Tradition::Datatypes; + +use Moose::Util::TypeConstraints; +use XML::Easy::Syntax qw( $xml10_name_rx ); + +enum 'Ternary' => [ qw( yes maybe no ) ]; + +enum 'RelationshipScope' => [ qw( local document global ) ]; + +subtype 'ReadingID', + as 'Str', + where { $_ =~ /\A$xml10_name_rx\z/ }, + message { 'Reading ID must be a valid XML attribute string' }; + +subtype 'SourceType', + as 'Str', + where { $_ =~ /^(xmldesc|plaintext|json|collation)$/ }, + message { 'Source type must be one of xmldesc, plaintext, json, collation' }; + +subtype 'Sigil', + as 'Str', + where { $_ =~ /\A$xml10_name_rx\z/ }, + message { 'Sigil must be a valid XML attribute string' }; + +1; \ No newline at end of file diff --git a/base/lib/Text/Tradition/Witness.pm b/base/lib/Text/Tradition/Witness.pm index 16fe172..69a5e66 100644 --- a/base/lib/Text/Tradition/Witness.pm +++ b/base/lib/Text/Tradition/Witness.pm @@ -3,10 +3,9 @@ package Text::Tradition::Witness; use vars qw( %tags ); use JSON; use Moose; -use Moose::Util::TypeConstraints; +use Text::Tradition::Datatypes; use Text::TEI::Markup qw( word_tag_wrap ); use TryCatch; -use XML::Easy::Syntax qw( $xml10_name_rx ); =head1 NAME @@ -184,18 +183,6 @@ if( $xpwit ) { # Enable plugin(s) if available eval { with 'Text::Tradition::WitLanguage'; }; -subtype 'SourceType', - as 'Str', - where { $_ =~ /^(xmldesc|plaintext|json|collation)$/ }, - message { 'Source type must be one of xmldesc, plaintext, json, collation' }; - -subtype 'Sigil', - as 'Str', - where { $_ =~ /\A$xml10_name_rx\z/ }, - message { 'Sigil must be a valid XML attribute string' }; - -no Moose::Util::TypeConstraints; - has 'tradition' => ( is => 'ro', isa => 'Text::Tradition',