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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.