summaryrefslogtreecommitdiff
path: root/lib/StarGit.pm
blob: 72933da1b402cd7f9bb52c334beee9d5d384fea5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package StarGit;
use Dancer ':syntax';

use StarGit::Graph;

our $VERSION = '0.1';

set serializer => 'JSON';

get '/' => sub {
    template 'index';
};

get '/graph/local/:name' => sub {
    my $name = params->{'name'};

    my $graph = StarGit::Graph->new( name => $name );
    $graph->neighbors( $name, 1 );
    $graph->remove_leaves();

    return _finalize($graph);
};

get '/graph/query' => sub {
    my $language = params->{language};

    my $graph = StarGit::Graph->new( language => $language );
    $graph->build_from_query();

    return _finalize($graph);
};

get '/graph/attributes' => sub {
    my $graph_settings = setting('graph');
    my $attributes     = $graph_settings->{attributes};
    return { attributes => $attributes };
};

sub _finalize {
    my $graph = shift;

    my @nodes = values %{ $graph->nodes };
    my @edges = values %{ $graph->edges };

    return { nodes => \@nodes, edges => \@edges, };
}

true;