package Autodoc; use strict; use JSON; use DBI; use warnings 'all'; use Exporter 'import'; our @EXPORT = qw(sqlconnect sqlquery load_conf); sub load_conf { my($file) = @_; my $x=''; die "No configuration file given" if !defined $file; open(F,"$file") || die "Failed to load configuration file"; while() { $x.=$_; } close(F); return from_json($x); } sub sqlconnect { my($sql) = @_; my $dsn = "DBI:mysql:database=$sql->{base};host=$sql->{host}"; my $dbh = DBI->connect($dsn, $sql->{user}, $sql->{pass}, { mysql_enable_utf8 => 1 }) || die "Failed to connect to database"; return $dbh; } sub sqlquery { my $dbh = shift; my $query = shift; my @args = @_; #print STDERR "$query\n"; my $sth = $dbh->prepare($query) || die "Failed to execute SQL query"; $sth->execute(@args) || die "Failed to execute SQL query"; return $sth; } return 1;