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 :

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


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;