new positioning system, works great for graph, needs work for CSV
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Segment.pm
1 package Text::Tradition::Collation::Segment;
2
3 use Moose;
4 use MooseX::NonMoose;
5
6 extends 'Graph::Easy::Node';
7
8 # A segment is a special 'invisible' node that is a set of Readings.
9 # We should never display these, but it is useful to have them
10 # available for many-to-many relationship mappings.
11
12 has 'members' => (
13     is => 'rw',
14     isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
15     required => 1,
16 );
17
18 sub FOREIGNBUILDARGS {
19     my $class = shift;
20     my %args = @_;
21
22     # Name the segment after its member elements.
23     my $nodename = join( ' ', map { $_->name } @{$args{'members'}} );
24     return ( 'name', $nodename );
25 }
26
27 sub BUILD {
28     my( $self, $args ) = @_;
29     $self->set_attribute( 'class', 'segment' );
30
31     foreach my $r ( @{$self->members} ) {
32         my $seg_edge = $r->parent->add_edge( $r, $self, 'segment' );
33         $seg_edge->set_attribute( 'class', 'segment' );
34     }
35 }
36
37 # For now, a segment has no position in the graph.  Eventually it might
38 # have the position of its first member.
39 sub has_position {
40     return undef;
41 }
42
43 no Moose;
44 __PACKAGE__->meta->make_immutable;
45
46 1;
47
48 ######################################################
49 ## copied from Graph::Easy::Parser docs
50 ######################################################
51 # when overriding nodes, we also need ::Anon
52
53 package Text::Tradition::Collation::Segment::Anon;
54 use Moose;
55 use MooseX::NonMoose;
56 extends 'Text::Tradition::Collation::Segment';
57 extends 'Graph::Easy::Node::Anon';
58 no Moose;
59 __PACKAGE__->meta->make_immutable;
60
61 1;
62 # use base qw/Text::Tradition::Collation::Segment/;
63 # use base qw/Graph::Easy::Node::Anon/;
64
65 ######################################################
66 # and :::Empty
67
68 package Text::Tradition::Collation::Segment::Empty;
69 use Moose;
70 use MooseX::NonMoose;
71 extends 'Graph::Easy::Node::Empty';
72 no Moose;
73 __PACKAGE__->meta->make_immutable;
74
75 1;
76 # use base qw/Text::Tradition::Collation::Segment/;
77
78 ######################################################