initial version

master
-m 2013-03-19 19:52:26 +01:00
commit ebd870b596
37 changed files with 10303 additions and 0 deletions

19
MANIFEST Normal file
View File

@ -0,0 +1,19 @@
MANIFEST
bin/app.pl
config.yml
environments/development.yml
environments/production.yml
views/index.tt
views/layouts/main.tt
MANIFEST.SKIP
lib/biblioteka.pm
public/css/style.css
public/css/error.css
public/404.html
public/dispatch.fcgi
public/javascripts/jquery.js
public/dispatch.cgi
public/500.html
t/002_index_route.t
t/001_base.t
Makefile.PL

13
MANIFEST.SKIP Normal file
View File

@ -0,0 +1,13 @@
^\.git\/
maint
^tags$
.last_cover_stats
Makefile$
^blib
^pm_to_blib
^.*.bak
^.*.old
^t.*sessions
^cover_db
^.*\.log
^.*\.swp$

21
Makefile.PL Normal file
View File

@ -0,0 +1,21 @@
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'biblioteka',
AUTHOR => q{YOUR NAME <youremail@example.com>},
VERSION_FROM => 'lib/biblioteka.pm',
ABSTRACT => 'YOUR APPLICATION ABSTRACT',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'YAML' => 0,
'Dancer' => 1.311,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'biblioteka-*' },
);

BIN
bin/.add_book.pl.swp Normal file

Binary file not shown.

BIN
bin/.app.pl.swp Normal file

Binary file not shown.

BIN
bin/a.db Normal file

Binary file not shown.

15
bin/add_book.pl Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/perl -w
use warnings;
use strict;
use strict 'vars';
use DBI;
my $dbfile = 'ksiazki.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
my$sth=$dbh->prepare("select * from ksiazki where id=(select max(id) from ksiazki)");
$sth->execute;
(my @dupa)=$sth->fetchall_arrayref;
my $max_id = ${$dupa[0]}[0][0];

66
bin/app.pl Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env perl
use warnings;
use strict;
use Dancer;
use DBI;
#Struktura bazy
#id, int; isbn, int; tytul, string; autor, string; owner, string; state, bool (czy pozyczona, 0=dostepna, 1=wzieta); type, bool (mozna brac ze soba? 1=tak, 0=nie)
my $dbfile = 'ksiazki.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
get '/' => sub
{
my $sth = $dbh->prepare("select * from ksiazki");
$sth->execute();
my @id;
my @isbn;
my @title;
my @author;
my @owner;
my @state;
my @type;
#my $result=''; #Poniewaz trzeba zwrocic string, wartosci kolejno pobierane z bazy,
#beda dodawane do zmiennej ze stringiem, na razie pustym
my $i=0;
my @result;
my $ii=0;
(@result)=@{$sth->fetchall_arrayref} or die "blad przy pobieraniu danych";
# |kolejne rekordy|kolejne pola rekordow
#return ${$result[2]}[4];
template 'a.tt',
{
'table' => \@result
}
};
get '/req/:book' => sub
{
my $id=params->{book};
my $sth;
$sth=$dbh->prepare("select type from ksiazki where id=?");
$sth->execute($id);
my $type = $sth->fetchrow_array;
if ($type == 1)
{
$sth = $dbh->prepare("update ksiazki set state=not state where id=?");
$sth->execute($id);
return 0;
}
elsif ($type == 0)
{
return 1;
}
else #Stalo sie cos dziwnego...
{
return "OMGLOLWTF";
}
};
dance;

63
bin/app.pl.backup Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env perl
use warnings;
use strict;
use Dancer;
use DBI;
#Struktura bazy
#id, int; isbn, int; tytul, string; autor, string; owner, string; state, bool (czy pozyczona, 0=dostepna, 1=wzieta); type, bool (mozna brac ze soba? 1=tak, 0=nie)
my $dbfile = 'ksiazki.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
get '/' => sub
{
my $sth = $dbh->prepare("select * from ksiazki");
$sth->execute();
my @id;
my @isbn;
my @title;
my @author;
my @owner;
my @state;
my @type;
my $result=''; #Poniewaz trzeba zwrocic string, wartosci kolejno pobierane z bazy,
#beda dodawane do zmiennej ze stringiem, na razie pustym
my $i=0;
while (($id[$i],$isbn[$i],$title[$i],$author[$i],$owner[$i],$state[$i],$type[$i])=$sth->fetchrow_array)
{
$result=$result.$id[$i].'|'.$isbn[$i].'|'.$title[$i].'|'.$author[$i].'|'.$owner[$i].'|'.$state[$i].'|'.$type[$i].'<br>'."\n";
$i++;
}
return $result;
};
get '/req/:book' => sub
{
my $id=params->{book};
my $sth;
$sth=$dbh->prepare("select type from ksiazki where id=$id");
$sth->execute();
my $type = $sth->fetchrow_array;
if ($type == 1)
{
$sth = $dbh->prepare("update ksiazki set state=not state where id=?");
$sth->execute($id);
return 0;
}
elsif ($type == 0)
{
return 1;
}
else #Stalo sie cos dziwnego...
{
return "OMGLOLWTF";
}
};
dance;

BIN
bin/ksiazki.db Normal file

Binary file not shown.

BIN
bin/ksiazki.db.backup Normal file

Binary file not shown.

BIN
bin/ksiazki.db.backup1 Normal file

Binary file not shown.

21
bin/test_sql.pl Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/perl
use DBI;
my $dbfile = 'a.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
#$dbh->do("create table abc (int a)");
#$dbh->do("insert into abc values (7)");
#print $dbh->do("select * from abc");
#my $sth = $dbh->prepare("select * from abc"); # prepare the query
#$sth->execute(); # execute the query
#my @row;
#while (@row = $sth->fetchrow_array) { # retrieve one row
# print join("\n", @row), "\n";
#}
my $sth = $dbh->prepare ("update qwe set liczba=20 where id=2");
$sth->execute();

32
config.yml Normal file
View File

@ -0,0 +1,32 @@
# This is the main configuration file of your Dancer app
# env-related settings should go to environments/$env.yml
# all the settings in this file will be loaded at Dancer's startup.
# Your application's name
appname: "biblioteka"
# The default layout to use for your application (located in
# views/layouts/main.tt)
layout: "main"
# when the charset is set to UTF-8 Dancer will handle for you
# all the magic of encoding and decoding. You should not care
# about unicode within your app when this setting is set (recommended).
charset: "UTF-8"
# template engine
# simple: default and very basic template engine
# template_toolkit: TT
#template_toolkit: Mojo::Template
#template: "simple"
template: 'mojo_template'
# template: "template_toolkit"
# engines:
# template_toolkit:
# encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'

View File

@ -0,0 +1,27 @@
# configuration file for development environment
# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: "console"
# the log level for this environment
# core is the lowest, it shows Dancer's core log messages as well as yours
# (debug, info, warning and error)
log: "core"
# should Dancer consider warnings as critical errors?
warnings: 1
# should Dancer show a stacktrace when an error is caught?
show_errors: 1
# auto_reload is a development and experimental feature
# you should enable it by yourself if you want it
# Module::Refresh is needed
#
# Be aware it's unstable and may cause a memory leak.
# DO NOT EVER USE THIS FEATURE IN PRODUCTION
# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
auto_reload: 0

View File

@ -0,0 +1,17 @@
# configuration file for production environment
# only log warning and error messsages
log: "warning"
# log message to a file in logs/
logger: "file"
# don't consider warnings critical
warnings: 0
# hide errors
show_errors: 0
# cache route resolution for maximum performance
route_cache: 1

1
git Normal file
View File

@ -0,0 +1 @@
http://git-scm.com/book/en/Getting-Started

0
ksiazki.db Normal file
View File

10
lib/biblioteka.pm Normal file
View File

@ -0,0 +1,10 @@
package biblioteka;
use Dancer ':syntax';
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
true;

18
public/404.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Error 404</title>
<link rel="stylesheet" href="/css/error.css" />
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Error 404</h1>
<div id="content">
<h2>Page Not Found</h2><p>Sorry, this is the void.</p>
</div>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a>.
</div>
</body>
</html>

18
public/500.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Error 500</title>
<link rel="stylesheet" href="/css/error.css" />
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Error 500</h1>
<div id="content">
<h2>Internal Server Error</h2><p>Wooops, something went wrong</p>
</div>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a>.
</div>
</body>
</html>

70
public/css/error.css Normal file
View File

@ -0,0 +1,70 @@
body {
font-family: Lucida,sans-serif;
}
h1 {
color: #AA0000;
border-bottom: 1px solid #444;
}
h2 { color: #444; }
pre {
font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace;
font-size: 12px;
border-left: 2px solid #777;
padding-left: 1em;
}
footer {
font-size: 10px;
}
span.key {
color: #449;
font-weight: bold;
width: 120px;
display: inline;
}
span.value {
color: #494;
}
/* these are for the message boxes */
pre.content {
background-color: #eee;
color: #000;
padding: 1em;
margin: 0;
border: 1px solid #aaa;
border-top: 0;
margin-bottom: 1em;
}
div.title {
font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace;
font-size: 12px;
background-color: #aaa;
color: #444;
font-weight: bold;
padding: 3px;
padding-left: 10px;
}
pre.content span.nu {
color: #889;
margin-right: 10px;
}
pre.error {
background: #334;
color: #ccd;
padding: 1em;
border-top: 1px solid #000;
border-left: 1px solid #000;
border-right: 1px solid #eee;
border-bottom: 1px solid #eee;
}

189
public/css/style.css Normal file
View File

@ -0,0 +1,189 @@
body {
margin: 0;
margin-bottom: 25px;
padding: 0;
background-color: #ddd;
background-image: url("/images/perldancer-bg.jpg");
background-repeat: no-repeat;
background-position: top left;
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
font-size: 13px;
color: #333;
}
h1 {
font-size: 28px;
color: #000;
}
a {color: #03c}
a:hover {
background-color: #03c;
color: white;
text-decoration: none;
}
#page {
background-color: #ddd;
width: 750px;
margin: auto;
margin-left: auto;
padding-left: 0px;
margin-right: auto;
}
#content {
background-color: white;
border: 3px solid #aaa;
border-top: none;
padding: 25px;
width: 500px;
}
#sidebar {
float: right;
width: 175px;
}
#header, #about, #getting-started {
padding-left: 75px;
padding-right: 30px;
}
#header {
background-image: url("/images/perldancer.jpg");
background-repeat: no-repeat;
background-position: top left;
height: 64px;
}
#header h1, #header h2 {margin: 0}
#header h2 {
color: #888;
font-weight: normal;
font-size: 16px;
}
#about h3 {
margin: 0;
margin-bottom: 10px;
font-size: 14px;
}
#about-content {
background-color: #ffd;
border: 1px solid #fc0;
margin-left: -11px;
}
#about-content table {
margin-top: 10px;
margin-bottom: 10px;
font-size: 11px;
border-collapse: collapse;
}
#about-content td {
padding: 10px;
padding-top: 3px;
padding-bottom: 3px;
}
#about-content td.name {color: #555}
#about-content td.value {color: #000}
#about-content.failure {
background-color: #fcc;
border: 1px solid #f00;
}
#about-content.failure p {
margin: 0;
padding: 10px;
}
#getting-started {
border-top: 1px solid #ccc;
margin-top: 25px;
padding-top: 15px;
}
#getting-started h1 {
margin: 0;
font-size: 20px;
}
#getting-started h2 {
margin: 0;
font-size: 14px;
font-weight: normal;
color: #333;
margin-bottom: 25px;
}
#getting-started ol {
margin-left: 0;
padding-left: 0;
}
#getting-started li {
font-size: 18px;
color: #888;
margin-bottom: 25px;
}
#getting-started li h2 {
margin: 0;
font-weight: normal;
font-size: 18px;
color: #333;
}
#getting-started li p {
color: #555;
font-size: 13px;
}
#search {
margin: 0;
padding-top: 10px;
padding-bottom: 10px;
font-size: 11px;
}
#search input {
font-size: 11px;
margin: 2px;
}
#search-text {width: 170px}
#sidebar ul {
margin-left: 0;
padding-left: 0;
}
#sidebar ul h3 {
margin-top: 25px;
font-size: 16px;
padding-bottom: 10px;
border-bottom: 1px solid #ccc;
}
#sidebar li {
list-style-type: none;
}
#sidebar ul.links li {
margin-bottom: 5px;
}
h1, h2, h3, h4, h5 {
font-family: sans-serif;
margin: 1.2em 0 0.6em 0;
}
p {
line-height: 1.5em;
margin: 1.6em 0;
}
code, tt {
font-family: 'Andale Mono', Monaco, 'Liberation Mono', 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', monospace;
}
#footer {
clear: both;
padding-top: 2em;
text-align: center;
padding-right: 160px;
font-family: sans-serif;
font-size: 10px;
}

15
public/dispatch.cgi Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env perl
use Dancer ':syntax';
use FindBin '$RealBin';
use Plack::Runner;
# For some reason Apache SetEnv directives dont propagate
# correctly to the dispatchers, so forcing PSGI and env here
# is safer.
set apphandler => 'PSGI';
set environment => 'production';
my $psgi = path($RealBin, '..', 'bin', 'app.pl');
die "Unable to read startup script: $psgi" unless -r $psgi;
Plack::Runner->run($psgi);

17
public/dispatch.fcgi Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env perl
use Dancer ':syntax';
use FindBin '$RealBin';
use Plack::Handler::FCGI;
# For some reason Apache SetEnv directives dont propagate
# correctly to the dispatchers, so forcing PSGI and env here
# is safer.
set apphandler => 'PSGI';
set environment => 'production';
my $psgi = path($RealBin, '..', 'bin', 'app.pl');
my $app = do($psgi);
die "Unable to read startup script: $@" if $@;
my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1);
$server->run($app);

9404
public/javascripts/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

5
t/001_base.t Normal file
View File

@ -0,0 +1,5 @@
use Test::More tests => 1;
use strict;
use warnings;
use_ok 'biblioteka';

10
t/002_index_route.t Normal file
View File

@ -0,0 +1,10 @@
use Test::More tests => 2;
use strict;
use warnings;
# the order is important
use biblioteka;
use Dancer::Test;
route_exists [GET => '/'], 'a route handler is defined for /';
response_status_is ['GET' => '/'], 200, 'response status is 200 for /';

24
views/a.tt Normal file
View File

@ -0,0 +1,24 @@
<html>
<body>
% (my @tab) = @{$_[0]->{'table'}};
<table border=7>
<tr><td>id</td><td>isbn</td><td>tytul</td><td>autor</td><td>wlasiciciel</td><td>jest?</td><td>mozna brac?</td></tr>
<tr>
% for (my $i=0;$i<$#tab;$i++)
% {
% for (my $ii=0;$ii<7;$ii++) #Jest 7 pol w kazdym rekordzie
% {
<td> <%= $tab[$i][$ii] %> </td>
% }
%= "\n"
</tr>
<tr>
% }
</table>
</body>
</html>

25
views/a.tt.backup Normal file
View File

@ -0,0 +1,25 @@
<html>
<body>
% (my @tab) = @{$_[0]->{'table'}};
% my $max_index = $#tab;
% my @pool_names = ('id','isbn', 'tytul', 'autor', 'wlasciciel', 'jest?', 'mozna brac?');
<table border=7>
<tr>id<td>isbn<td>tytul<td>autor<td>wlasiciciel<td>jest?<td>mozna brac?
<tr>
% for (my $i=0;$i<$max_index;$i++)
% {
% for (my $ii=0;$ii<7;$ii++) #Jest 7 pol w kazdym rekordzie
% {
%# = $pool_names[$ii].':'.$tab[$i][$ii]
%# <tr> <%= $pool_names[$ii] %> <td> <%= $tab[$i][$ii] %>
<td> <%= $tab[$i][$ii] %>
% }
%= "\n"
<tr>
% }
</table>
</body>
</html>

12
views/a.tt.backup1 Normal file
View File

@ -0,0 +1,12 @@
<html>
<body>
% my ($x) = @_;
% my @tab = $x->{'table'};
%# my $max_index = $#tab;
%# for (my $i=0;$i<$max_index;$i++)
%# {
%= $tab[0][1][3]
%# }
</body>
</html>

10
views/b.tt Normal file
View File

@ -0,0 +1,10 @@
<html>
<body>
<table>
<table border=7>
<tr>
<td> <%=5*5%> </td>
</tr>
</table>
</body>
</html>

6
views/c.tt Normal file
View File

@ -0,0 +1,6 @@
<html>
<body>
%my ($x) = @_;
%= $x->{'number'};
</body>
</html>

148
views/index.tt Normal file
View File

@ -0,0 +1,148 @@
<!--
Credit goes to the Ruby on Rails team for this page
has been heavily based on the default Rails page that is
built with a scaffolded application.
Thanks a lot to them for their work.
See Ruby on Rails if you want a kickass framework in Ruby:
http://www.rubyonrails.org/
-->
<div id="page">
<div id="sidebar">
<ul id="sidebar-items">
<li>
<h3>Join the community</h3>
<ul class="links">
<li><a href="http://perldancer.org/">PerlDancer</a></li>
<li><a href="http://twitter.com/PerlDancer/">Official Twitter</a></li>
<li><a href="https://github.com/sukria/Dancer/">GitHub Community</a></li>
</ul>
</li>
<li>
<h3>Browse the documentation</h3>
<ul class="links">
<li><a
href="http://search.cpan.org/dist/Dancer/lib/Dancer/Introduction.pod">Introduction</a></li>
<li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Cookbook.pod">Cookbook</a></li>
<li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Deployment.pod">Deployment Guide</a></li>
<li><a
href="http://search.cpan.org/dist/Dancer/lib/Dancer/Tutorial.pod"
title="a tutorial to build a small blog engine with Dancer">Tutorial</a></li>
</ul>
</li>
<li>
<h3>Your application's environment</h3>
<ul>
<li>Location: <code>/home/cranix/Biblioteka/biblioteka</code></li>
<li>Template engine: <code><% settings.template %></code></li>
<li>Logger: <code><% settings.logger %></code></li>
<li>Environment: <code><% settings.environment %></code></li>
</ul>
</li>
</ul>
</div>
<div id="content">
<div id="header">
<h1>Perl is dancing</h1>
<h2>You&rsquo;ve joined the dance floor!</h2>
</div>
<div id="getting-started">
<h1>Getting started</h1>
<h2>Here&rsquo;s how to get dancing:</h2>
<h3><a href="#" id="about_env_link">About your application's environment</a></h3>
<div id="about-content" style="display: none;">
<table>
<tbody>
<tr>
<td>Perl version</td>
<td><tt><% perl_version %></tt></td>
</tr>
<tr>
<td>Dancer version</td>
<td><tt><% dancer_version %></tt></td>
</tr>
<tr>
<td>Backend</td>
<td><tt><% settings.apphandler %></tt></td>
</tr>
<tr>
<td>Appdir</td>
<td><tt>/home/cranix/Biblioteka/biblioteka</tt></td>
</tr>
<tr>
<td>Template engine</td>
<td><tt><% settings.template %></tt></td>
</tr>
<tr>
<td>Logger engine</td>
<td><tt><% settings.logger %></tt></td>
</tr>
<tr>
<td>Running environment</td>
<td><tt><% settings.environment %></tt></td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$('#about_env_link').click(function() {
$('#about-content').slideToggle('fast', function() {
// ok
});
return( false );
});
</script>
<ol>
<li>
<h2>Tune your application</h2>
<p>
Your application is configured via a global configuration file,
<tt>config.yml</tt> and an "environment" configuration file,
<tt>environments/development.yml</tt>. Edit those files if you
want to change the settings of your application.
</p>
</li>
<li>
<h2>Add your own routes</h2>
<p>
The default route that displays this page can be removed,
it's just here to help you get started. The template used to
generate this content is located in
<code>views/index.tt</code>.
You can add some routes to <tt>lib/biblioteka.pm</tt>.
</p>
</li>
<li>
<h2>Enjoy web development again</h2>
<p>
Once you've made your changes, restart your standalone server
(bin/app.pl) and you're ready to test your web application.
</p>
</li>
</ol>
</div>
</div>
</div>

0
views/ksiazki.db Normal file
View File

20
views/layouts/main.tt Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=<% settings.charset %>" />
<title>biblioteka</title>
<link rel="stylesheet" href="<% request.uri_base %>/css/style.css" />
<script type="text/javascript">/* <![CDATA[ */
!window.jQuery && document.write('<script type="text/javascript" src="<% request.uri_base %>/javascripts/jquery.js"><\/script>')
/* ]]> */</script>
</head>
<body>
<% content %>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a> <% dancer_version %>
</div>
</body>
</html>

7
views/q.tt Normal file
View File

@ -0,0 +1,7 @@
<html>
<body>
% my ($x) = @_;
% my @tab = $x->{'tablica'};
%= ${$tab[0]}[0]
</body>
</html>