File: Util.pm

package info (click to toggle)
libweb-solid-auth-perl 0.91-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 1,344; makefile: 5; sh: 1
file content (42 lines) | stat: -rw-r--r-- 850 bytes parent folder | download | duplicates (2)
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
package Web::Solid::Auth::Util;

use Moo;
use Attean;
use Attean::RDF qw(iri);

our $GNAME = 'http://graph-name/'; 

sub parse_turtle {
    my ($self, $turtle) = @_;

    my $store  = Attean->get_store('Memory')->new();
    my $parser = Attean->get_parser('Turtle')->new();
    
    my $iter = $parser->parse_iter_from_bytes($turtle);

    return undef unless $iter;

    my $graph = iri($GNAME);
    my $quads = $iter->as_quads($graph);

    $store->add_iter($quads);

    my $model = Attean::QuadModel->new( store => $store );

    return $model;
}

sub sparql {
    my ($self, $model, $sparql, $cb) = @_;

    my $s = Attean->get_parser('SPARQL')->new();
    my ($algebra) = $s->parse($sparql);
    my $graph = iri($GNAME);
    my $results = $model->evaluate($algebra, $graph);

    while (my $r = $results->next) {
        $cb->($r);
    }
}

1;