## NOTE : Very simple example which for the most part
## will seem like overkill and it is.  Typically the complexity
## of the application can be reduced by breaking it into the
## components below.  It makes for easier maintenance.

## Model responsible for data retrieval not formatting.
##In many architectures data will be retrieved from
## some sort of data storage (rdbms).
#--- MODEL ---
package My::Model

sub title { return 'MVC Hello World Example'; }
sub new { return bless {}, shift };
sub enter_room { return 'Hello'; }
sub leave_room { return 'Bye'; }

## Responisble for presentation/formatting of data not
## modifying/retrieving data.
#--- VIEW ---
package My::View

sub new { return bless {}, shift };
sub output {
  my $p = { @_ };

  print <<HTML;
<html>
<head>
<title>$p->{'title'}</title>
</head>
<body>
<h1>$p->{'data'}</h1>
</html>
HTML
}

## Handles user actions/events ... retrieve data through
## model layer and present data through view layer.
#--- CONTROLLER ----

## Depending on the application (CGI, etc.) initialization code here

my $m = My::Model->new;
my $v = My::View->new;

my $data = $m->leave_room;

if ( $input == 'enter_room' ) {
        $data = $m->enter_room;
}

$v->output(
        title=> $v->title,
        data=> $data,
);


  I too would like to would like to have a better understanding of how
  MVC can be applied to mod_perl.  Maybe even HelloWorld sized example
  showing how all of the different components interact?



Reply via email to