Class-MVC
view release on metacpan or search on metacpan
my $this = shift;
$this->controller( ( ref($this).'::Controller' )->new() );
$this->model( ( ref($this).'::Model' )->new() );
$this->view( ( ref($this).'::View' )->new() );
}
sub _postinit : method
{
my $this = shift;
$this->interconnect();
}
sub interconnect : method
{
my $this = shift;
$this->view->model( $this->model ) if $this->model;
$this->view->controller( $this->controller ) if $this->controller;
$this->controller->model( $this->model ) if $this->model;
$this->controller->view( $this->view ) if $this->view;
$this->model->add_observer( $this->view ) if $this->view;
}
package Class::MVC::Model;
Class::Maker::class
{
isa => [qw( Class::Observable )],
};
sub DESTROY
{
my $this = shift;
$this->delete_observers;
}
package Class::MVC::View;
Class::Maker::class
{
isa => [qw( Class::Listener )],
public =>
{
ref => [qw( controller model )],
},
};
# dispatch method for Observer ( see Class::Observable )
sub update : method
{
my $this = shift;
my ( $object, $action ) = @_;
return $this->Class::Listener::signal( $action, $object );
}
package Class::MVC::CompositeView;
Class::Maker::class
{
isa => [qw( Class::MVC::View )],
public =>
{
# The subView/superView relationship
ref => [qw( super_view )],
},
};
# not implemented
sub sub_views : method
{
my $this = shift;
}
sub update : method
{
my $this = shift;
# update yourself
$this->SUPER::update( @_ );
# and your superviews
$this->super_view->update( @_ ) if $this->super_view;
}
package Class::MVC::Controller;
Class::Maker::class
{
public =>
{
ref => [qw( model view )],
},
};
sub _postinit : method
{
my $this = shift;
}
sub update_model : method
{
my $this = shift;
# call Model methods from here
$this->model->Class::Listener::signal( 'update', $this, @_ );
}
sub change_view : method
{
my $this = shift;
# call View methods from here
$this->view->Class::Listener::signal( 'change', $this, @_ );
}
1;
__END__
=pod
=head1 NAME
Class::MVC - model-view-controller paradigma
=head1 SYNOPSIS
use Class::Maker 'class';
use Class::MVC;
class 'Widget',
{
isa => [qw( Class::MVC )]
};
class 'Widget::ViewModel',
{
isa => [qw( Device::Output::Channel )],
public =>
{
string => [qw( info )],
},
};
class 'Widget::Model',
{
isa => [qw( Class::MVC::Model Shell::Widget::ViewModel)],
};
class 'Widget::View',
{
isa => [qw( Class::MVC::CompositeView )],
public =>
{
ref => [qw( device )],
( run in 0.910 second using v1.01-cache-2.11-cpan-13bb782fe5a )