Skip to content

Instantly share code, notes, and snippets.

@jeffa
Last active February 24, 2017 03:15
Show Gist options
  • Select an option

  • Save jeffa/107b2de63ace11a17f4a to your computer and use it in GitHub Desktop.

Select an option

Save jeffa/107b2de63ace11a17f4a to your computer and use it in GitHub Desktop.
Minimal example of an MVC implementation
#!/usr/bin/perl -l
package Model;
use Moose;
has state => ( is => 'ro', reader => 'get_state', default => 0 );
sub set_state { $_[0]->{state} += $_[1] }
package View;
use Moose;
sub update_display { print $_[1]->get_state }
package Controller;
use Moose;
has model => ( is => 'ro', default => sub { Model->new } );
has view => ( is => 'ro', default => sub { View->new } );
sub run {
my ($model, $view) = ($_[0]->model, $_[0]->view);
for (1, 5, 8, -20, 5, 2) {
$model->set_state( $_ );
$view->update_display( $model );
}
}
package main;
Controller->new->run;
@jeffa
Copy link
Copy Markdown
Author

jeffa commented May 14, 2015

I have since learned that the View should start the engine, not the Controller. Live and learn. 🍕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment