DBIx::Class - Related Tables

Andy Wardley abw at wardley.org
Tue Oct 7 11:51:35 BST 2008

Paul Makepeace wrote:
> One aspect, that befalls any abstraction system, is that you run into
> a situation where a lot of work is being hidden behind a simple
> interface.

True, although this is something that can be easily mitigated with a
bespoke object method or two and an orcish manoeuvre.

   package My::User;

   use base 'My::Database::Record';

   sub roles {
       my $self = shift;
       return $self->{ roles } ||= {
	  map { $_->role => $_ }
           $self->model->roles->fetch( user_id => $self->{ id } )

   sub has_role {
       my ($self, $role) = @_;
       return $self->roles->{ $role };

These kind of methods can be auto-generated quite easily.

Nevertheless, it does require someone to think about these kind of
issues and design the system accordingly.


More information about the london.pm mailing list