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


In reply to Mouse role fails by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.