| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | use strictscip-perl cpan RDF-Trine 1.019 strict/; |
| 4 | use warningsscip-perl cpan RDF-Trine 1.019 warnings/; |
| 5 | no warnings 'redefine'; |
| 6 | use File::Specscip-perl cpan RDF-Trine 1.019 File/Spec/; |
| 7 | use File::Slurpscip-perl cpan RDF-Trine 1.019 File/Slurp/; |
| 8 | use LWP::UserAgentscip-perl cpan RDF-Trine 1.019 LWP/UserAgent/; |
| 9 | use Data::Dumperscip-perl cpan RDF-Trine 1.019 Data/Dumper/; |
| 10 | |
| 11 | use RDF::Trinescip-perl cpan RDF-Trine 1.019 RDF/Trine/; |
| 12 | use RDF::Trine::Modelscip-perl cpan RDF-Trine 1.019 RDF/Trine/Model/; |
| 13 | use RDF::Trine::Serializer::NTriplesscip-perl cpan RDF-Trine 1.019 RDF/Trine/Serializer/NTriples/; |
| 14 | use RDF::Trine::Store::DBIscip-perl cpan RDF-Trine 1.019 RDF/Trine/Store/DBI/; |
| 15 | use RDF::Trine::Statementscip-perl cpan RDF-Trine 1.019 RDF/Trine/Statement/; |
| 16 | |
| 17 | unless (@ARGVscip-perl cpan RDF-Trine 1.019 main/`@ARGV`. >= 4) { |
| 18 | printscip-perl cpan RDF-Trine 1.019 main/print(). <<"END"; |
| 19 | USAGE: $0 server-type dbname username password model-name [host] |
| 20 | |
| 21 | server-type can be either 'mysql' or 'sqlite' |
| 22 | |
| 23 | |
| 24 | END |
| 25 | exitscip-perl cpan RDF-Trine 1.019 main/exit().; |
| 26 | } |
| 27 | |
| 28 | my $server = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 29 | my $dbname = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 30 | my $user = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 31 | my $pass = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 32 | my $modelname = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 33 | my $host = shiftscip-perl cpan RDF-Trine 1.019 main/shift().; |
| 34 | |
| 35 | my $dsn; |
| 36 | if ($server eq 'mysql') { |
| 37 | $dsn = "DBI:mysql:database=${dbname}"; |
| 38 | } elsif ($server eq 'sqlite') { |
| 39 | $dsn = "DBI:SQLite:dbname=${dbname}"; |
| 40 | } elsif ($server eq 'pg') { |
| 41 | $dsn = "DBI:Pg:dbname=${dbname}"; |
| 42 | if ($host) { |
| 43 | $dsn .= ';host=' . $host; |
| 44 | } |
| 45 | } else { |
| 46 | warnscip-perl cpan RDF-Trine 1.019 main/warn(). "Unknown server type: $server\n"; |
| 47 | exitscip-perl cpan RDF-Trine 1.019 main/exit().; |
| 48 | } |
| 49 | |
| 50 | my $store = RDF::Trine::Store::DBI->newscip-perl cpan RDF-Trine 1.019 RDF/Trine/Store/DBI/new().($modelname, $dsn, $user, $pass); |
| 51 | my $model = RDF::Trine::Model->newscip-perl cpan RDF-Trine 1.019 RDF/Trine/Model/new().($store); |
| 52 | |
| 53 | my $serializer = RDF::Trine::Serializer::NTriples->newscip-perl cpan RDF-Trine 1.019 RDF/Trine/Serializer/NTriples/new().(); |
| 54 | $serializer->serialize_model_to_filescip-perl cpan RDF-Trine 1.019 RDF/Trine/Serializer/NTriples/serialize_model_to_file().( \*STDOUT, $model ); |
| 55 | |
| 56 | if (0) { |
| 57 | my $iter = $store->get_statementsscip-perl cpan RDF-Trine 1.019 RDF/Trine/Store/DBI/get_statements().(); |
| 58 | |
| 59 | while (my $s = $iter->nextscip-perl cpan RDF-Trine 1.019 main/next().) { |
| 60 | printscip-perl cpan RDF-Trine 1.019 main/print(). $s->as_stringscip-perl cpan RDF-Trine 1.019 main/as_string(). . "\n"; |
| 61 | } |
| 62 | } |