package Dojo::Model::Vuelo; use Mojo::File 'path'; use Mojo::JSON qw(decode_json encode_json); use Dojo::Support qw{ dmph merge_hash load_module }; use File::Basename; use Text::Markdown qw{ markdown }; use Encode qw{ decode_utf8 }; use DBI; use Dojo::Conf; sub new { bless {}, shift }; sub mod{ my $q="select nombre,contenido from casa;"; return \@{_read($q,$vuelo)}; } sub pang{ my ($c,$q)=@_; return {map { basename($_,".md") => load_md("public/$_")}@{$q->{md}}}; } sub cal { my $block=_read (path("public/home/cal/q1Block.q")->slurp,$vuelo); my $data=_read (path("public/home/cal/q3Event.q")->slurp,$vuelo); return ($data,$block); } sub event{ my ($self,$id)=@_; return _read (path("public/home/event/qEvent.q")->slurp,$vuelo,$id); } sub store{ return _read (path("public/home/store/qStore.q")->slurp,$vuelo); } sub tv{ my $series = _read (path("public/home/tv/qSeries.q")->slurp,$vuelo); #group,name my $table = _read (path("public/home/tv/qTable.q")->slurp,$vuelo); #name,order,group return ($series,$table); } sub podcast{ my $txt = path("public/home/podcast/text.txt")->slurp; my $hash = decode_json path("public/home/podcast/jsonPod.json")->slurp; return ($txt,$hash); } sub radio{ my $q="select contenido as rmod from casa where nombre='rmod';"; return _read($q,$vuelo); } sub _read{ my ($q,$d,@bind)=@_; my (@empty,$arr); my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VUELODB.":".Dojo::Conf::VUELODB_H,Dojo::Conf::VUELODB_UR,Dojo::Conf::VUELODB_URP); return \@empty unless($dbh); #$dbh->do(qq{SET NAMES 'utf8'}); my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind); #((col1=>d1,col2=>d1),(col1=>d2,col2=>d2)) $dbh->disconnect(); return $h; } sub load_md{ return "" unless my $text = path(shift)->slurp; return markdown( decode_utf8($text) ); } sub load_txt{ return "" unless my $text = path(shift)->slurp; return decode_utf8($text); } 1;