Yote Hello World Example

# Yote Application Server Hello World Example

Get Yote on github : https://github.com/ewolf/Yote

## Hello World

## What's going on here?

> Yote provides javascript objects that are linked to perl objects running in an application server. These perl objects get the following features :

> - Automatic Persistance without a schema.
> - idiomatic getters and setters for fields. Calling set_foo("bar") on a Yote object automatically creates and populates the field 'foo'. Calling get_foo("bar") returns the value of foo, populating it with 'bar' if its not yet defined. Fields may contain scalars, hashes, arrays and Yote objects.
> - more syntactic sugar : add_to_mylist, remove_from_mylist causes an array field 'mylist' to be created and populated
> - Circular References are allowed
> - public methods (beginning with a lower case letter) may be invoked by javascript objects
> - Methods for creating accounts, logging in
> - Tokens can be used for logging in, and are linked to IP
> - Passwords are not plaintext.
> - Ability to limit access to which accounts may access which methods or objects
> - Yote object method execution is thread-safe. Yote web application server receives messages in different threads, but has a single threaded execution process.

> Once Yote has been set up, the client and server are written as described below.

> - The client contacts the server and gets the (singleton) root app with the perl package name (Yote::Hello).
> - The hello method is called on the app and its response is stored in result.

## Client Side Code

>     <html><head><title>Hello World</title>
>     <script src="./js/jquery-latest.js"></script>
>     <script src="./js/jquery.dumper.js"></script>
>     <script src="./js/jquery.base64.min.js"></script>
>     <script src="./js/json2.js"></script>
>     <script src="./js/yote.js"></script>
>     <script>
>       $().ready(function(){
>           var hello_app = $.yote.init("http://"+location.host+"/cgi-bin/yote.cgi").get_app('Yote::Hello');
>           $('#button').click( function() {
>               var result = hello_app.hello({ name:$('#txt').val() } );
>               alert( result ); //get the message from running the hello method.
>               alert( 'testfield is ' + hello_app.get_testfield() ); //get the value of testfield that is attached to the app
>               var counter = hello_app.get_counter();                //get the counter object that is attached to the app
>               alert( 'counter is at ' + counter.get_count() );      //get the value of the count field of the counter object attached to the app
>           } );

>       });
>     </script></head>
>     <body><h1>Hello World</h1>
>     <input type=text id=txt><BR><button type=button id=button>Say Hi</button>
>     </body></html>

## Server Side Code

>     package Yote::Hello;

>     use strict;

>     use Yote::Obj;

>     use base 'Yote::AppRoot';

>     sub init {
>         my $self = shift;
>         #when the hello is created for the first time, install a counter to track how many times it is called
>         $self->set_counter( new Yote::Obj() );
>     }

>     sub hello {
>         my( $self, $data, $acct ) = @_;
>         my $name = $data->{name};
>         $self->set_testfield(int(rand(10)); # set this to a random value each time
>         my $counter = $self->get_counter(); # this could be counted with a field, but I wanted to demo how easy it is to send objects across.
>         $counter->set_count( $counter->get_count() + 1 ); #increment the value in the counter
>         return { r => "hello there '$name'. I have said hello ".$counter->get_count()." times." };
>     }

>     1;