diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-07-16 11:19:15 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-07-16 11:19:15 +0200 |
| commit | faf6949033a021bffab3c91a04665efef4378b28 (patch) | |
| tree | 48f04f0f373f3c2067216d76eaeb9f0e4badf339 /lib/Graph/GEXF/Node.pm | |
| download | graph-gexf-faf6949033a021bffab3c91a04665efef4378b28.tar.gz | |
basic gexf generation
Diffstat (limited to 'lib/Graph/GEXF/Node.pm')
| -rw-r--r-- | lib/Graph/GEXF/Node.pm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/Graph/GEXF/Node.pm b/lib/Graph/GEXF/Node.pm new file mode 100644 index 0000000..0c45a04 --- /dev/null +++ b/lib/Graph/GEXF/Node.pm @@ -0,0 +1,50 @@ +package Graph::GEXF::Node; + +use Moose; + +use Graph::GEXF::Edge; +with 'Graph::GEXF::Role::Attributes' => {for => [qw/node/]}; + +has id => (is => 'ro', isa => 'Str', required => 1); +has label => (is => 'rw', isa => 'Str'); + +has edges => ( + traits => ['Hash'], + is => 'rw', + isa => 'HashRef[Graph::GEXF::Edge]', + default => sub { {} }, + handles => { + add_edge => 'set', + has_link_to => 'exists', + all_edges => 'keys', + get_edge => 'get', + } +); + +sub link_to { + my $self = shift; + my @nodes_id = @_; + + foreach my $node_id (@nodes_id) { + my $edge = + Graph::GEXF::Edge->new(source => $self->id, target => $node_id); + + $self->add_edge($node_id => $edge); + } +} + +sub attribute { + my ($self, $attribute_name, $value) = @_; + +# return 0 unless $self->has_node_attribute; + + if (!$self->has_node_attribute($attribute_name)) { + die "this attribute doesn't exists"; + } + + $self->node_attributes->{$attribute_name}->{value} = $value; + + 1; +} + +1; |
