forked from ewolf/Yote
/
README
151 lines (114 loc) · 4.63 KB
/
README
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Name
YOTE
Summary
Yote is a platform for creating web based applications by bridging
client side javascript with server side, automatically persistent perl
objects. Yote provides javascript objects with methods that map to their
server side counterparts.
Yote also is a simple web server as well as an app server.
Note
As of this writing Yote is on version 0.086.
It is not yet stable and is in pre-alpha mode.
Consider this alpha software once version 0.100 is reached.
Please email coyocanid@gmail.com to report bugs or issues or
feature requests.
Requirements
* perl version 5.10
Install Yote
$ export INSTALL_BASE=/usr/local/yote #optional. default is /usr/local/yote
$ export YOTEPORT=8008 #optional #optional. default is 8008
$ # Thru CPAN ---
$ cpan Yote
$ # OR ---
$ perl Build.PL
$ ./Build
$ ./Build test
$ ./Build install
Verify by running html test
$ yote_server
open http://<myhost>/yote/unit_tests.html
Using Yote
Start the Web App Server
Starting the Web App Server from the command line:
$ yote_server --port=8008 # default is port set up with, or 8008
This starts the server on the default port (8008), using SQLiteIO, and
writing to file ~/.yote/SQLite.yote.db.
Starting the Web App Server from a package:
use Yote::WebAppServer;
my $server = new Yote::WebAppServer();
$server->start_server( port => 8008,
webroot => 'path/to/my/html/files',
sqlitefile => 'yote.database_filename' );
Coding with Yote
Client Side
<script src="/yote/js/jquery-latest.js"></script>
<script src="/yote/js/jquery.dumper.js"></script>
<script src="/yote/js/jquery.cookie.js"></script>
<script src="/yote/js/jquery.base64.min.js"></script>
<script src="/yote/js/json2.js"></script>
<script src="/yote/js/yote.js"></script>
<script src="/yote/js/yote.util.js"></script>
<script src="/yote/js/yote.system.util.js"></script>
<script>
$.yote.init();
/* Get the account root singleton object. */
var hello_app = $.yote.fetch_app( 'Yote::Hello' );
/* Returns a string. If the method results in changes in other
javascript objects, those objects will automatically be updated. */
var result = hello_app.hello( { name:"fred" } );
/* Returns a counter object */
var counter = hello_app.get_counter();
alert( 'server said ' + result );
alert( 'counter in server has count of ' + counter.get_count() );
</script>
Server Side
package Yote::Hello;
use strict;
use Yote::Obj;
#
# Any subclass of Yote::AppRoot will have a singleton instance in the Yote engine
# that will be returned to the client with '$.yote.fetch_app( "app classname" )'.
#
use base 'Yote::AppRoot';
#
# Init is called only the very first time an Yote::AppRoot is instantiated.
# This is not called when this object is retreived from storage.
#
sub init {
my $self = shift;
#
# 'get_counter' does not need an explicit definition.
# A get_ method passed an argument will initialize the field if it is undefined.
#
my $counter = $self->get_counter( new Yote::Obj() );
} #init
#
# Any server side method takes 3 optional arguments on the client side :
# data, onSucceedFunction, onFailFunction
#
# Conversely, any server side method takes 3 automatically passed parameters :
# self, data, account.
#
# The argument { name => "wilma" } is passed to the $data parameter of the method.
#
# If a user is logged in to Yote on the client, that user's account will automatcially
# be passed into the server side method as the last argument. The account object is
# a Yote::Obj object meant to store any information specific to the user *and* this
# applications. A user will get a different account object for each different App.
#
sub hello {
my( $self, $data, $acct ) = @_;
my $name = $data->{name};
my $counter = $self->get_counter();
#
# 'set_count' does not need an explicit definition.
#
$counter->set_count( $counter->get_count() + 1 );
#
# The return value is a string in this case.
# var msg = hello_app.hello({name:"foo"});
# msg will be the string "hello there 'foo'."
#
return "hello there '$name'. I have said hello ". $counter->get_count() . " times.";
} #hello
1;