http://www.perlmonks.org?node_id=1001962
karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i'm playing around with Mouse roles and got stuck.

Role #1:

package ReadFile; use Mouse::Role; use MyTypes; use IO::File; requires qw(lines); has '_io' => ( is => 'ro', isa => 'MyCompany::ReadFile', builder => '_build_read_file', handles => [ qw( open getlines close) ], init_arg => undef, lazy => 1, ); sub _build_read_file() { my $self = shift; IO::File->new(); } # sub read_file() { # my ( $self, $file ) = @_; # $self->open( $file); # my @lines = $self->getlines(); # $self->close(); # chomp(@lines); # $self->lines(\@lines); # } 1;

This one fails on init with the followings errors:

Could not load class (ReadFile) because : Undefined subroutine &IO::Handle::_create_getline_subs called at C:/strawberry/perl/lib/IO/Handle.pm line 434.

In Handle.pm Line 434: # Special XS wrapper to make them inherit lexical hints from the caller. _create_getline_subs(<<'END' ) or die $@;

Compilation failed in require at C:/strawberry/perl/lib/IO/Seekable.pm line 101.

In Seekable.pm line 101: use IO::Handle ();

Compilation failed in require at C:/strawberry/perl/lib/IO/File.pm line 133.

In File.pm line 133: use IO::Seekable;

But the next one works.

Role #2:

package DBIxODBC; use Mouse::Role; use MyTypes; use DBIx::Simple; requires qw( user passwd dsn ); with qw(Timestamp); has 'data' => ( is => 'rw', isa => 'HashRef', trigger => \&_load, ); has '_dbix' => ( is => 'ro', isa => 'MyCompany::DBIx', handles => [qw( insert)], builder => '_build_dbix', init_arg => undef, lazy => 1, ); sub _build_dbix() { my $self = shift; my $connect_string; $connect_string = "dbi:ODBC:" . $self->dsn; DBIx::Simple->new( $connect_string, $self->user, $self->passwd ); } sub _load() { my ( $self, $input ) = @_; my $table = ( keys %$input )[0]; $self->insert( $table, $input->{$table} ); print $self->timestamp . qq(\n); } 1;

Thank you very much for any advice.

Best regards,

Karl