On Wed, Aug 11, 2010 at 3:09 PM, Ian Docherty (icydee) <
[email protected]>
>
> When you say 'the tests are forgotten' I assume you mean that people
> accessed and modified the DBIC objects directly from within the application?
> (For example, by forgetting to call the $foo->set_active method but calling
> the $foo->active(1) method instead?)
>
No, what I meant is we have been doing what you describe:
> package MyApp::Business::Label;
> use Moose;
>
> has 'dbic_obj' => (is => 'ro', required => 1);
>
> sub set_active {
> my ($self) = @_;
>
> die "Is Readonly" if $self->dbic_obj->is_readonly;
>
> $self->dbic_obj->active( 1 );
> $self->dbic_obj->update;
> }
>
In a very large application with a large number of methods like that. Then
each one must have that is_readonly test. It's a lot of repeating. Of
course, the tests are much more complex.
As developers come and go over time we have had cases where new methods are
added but the validation code is left off or just misunderstood. That is,
they might forget to add:
die "Is Readonly" if $self->dbic_obj->is_readonly;
So to avoid repeating and copying code instead:
sub set_active {
my ($self) = @_;
$self->dbic_obj->active( 1 );
$self->update;
}
And in a base class:
sub update {
my $self = shift;
die "Object $self is readonly" if $self->dbic_obj->is_readonly;
$self->dbic_obj->update;
}
Again, that's pretty close to the dbic layer, so I'm not sure there's much
advantage of that over wrapping DBIC's update() directly.
> This is not all that different from your example, but it would be fairly
> obvious if someone was accessing the ORM directly from your application
> since you would see the use of the 'dbic_obj' accessor.
>
True, that does provide some isolation.
This app provides a REST-like http interface. All access to the app is via
that interface -- including even cron jobs -- which means the DBIC objects
are completely isolated. The boundaries between the "app" and "model" are
not always that clear.
--
Bill Moseley
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]