新しいblogに移行しました

新ブログ "All Yout Bugs Are Belong To Ass" に移行しました!

ラベル Moose の投稿を表示しています。 すべての投稿を表示
ラベル Moose の投稿を表示しています。 すべての投稿を表示

2009-07-29

[Perl]List-MoreUtils-0.24はPerl5.8.8以前には入らない

7/27にList-MoreUtils-0.24がリリースされました。
しかしPerl5.8.8だと、testコケます。
Reports for List-MoreUtils

Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/0_pod.t .............. ok
t/0_pod_coverage.t ..... skipped: Test::Pod::Coverage not installed
t/List-MoreUtils-pp.t .. ok
t/List-MoreUtils.t ..... Use of uninitialized value in numeric eq (==) at t/List-MoreUtils.t line 45.
Use of uninitialized value in numeric eq (==) at t/List-MoreUtils.t line 45.
Use of uninitialized value in numeric eq (==) at t/List-MoreUtils.t line 45.
t/List-MoreUtils.t ..... Failed 2173/2173 subtests

Test Summary Report
-------------------
t/List-MoreUtils.t (Wstat: 11 Tests: 0 Failed: 0)
Non-zero wait status: 11
Parse errors: Bad plan. You planned 2173 tests but ran 0.
Files=4, Tests=2164, 9 wallclock secs ( 2.58 usr 0.25 sys + 5.56 cusr 0.54 csys = 8.93 CPU)
Result: FAIL
Failed 1/4 test programs. 0/2164 subtests failed.


今のところPerl5.8.8では、0.22を使うしかなさそうです。
ちなみにMooseもこのモジュール使ってます。なので、Moose使うときには予めList-MoreUtils-0.22入れてからMooseを入れないとずっこけます。

2009-09-14 追記
現在、0.24は無かったことになっているようです。
その代わりに Developer Release として0.25_02がリリース済みです。こちらはPerl5.8.8でもテストが通る様ですが、メモリリークしてたりするようなので、もう少々0.22に頑張ってもらうことになりそうです。

2009-07-24

[Perl]MooseX::Types::DateTime::ButMaintained-0.08がテストコケる

MooseX::Types::DateTimeXを入れてるときにコケた。

Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/01_basic.t t/02_olson_abbreviations.t t/03_local_floating.t
t/01_basic.t ................ 12/?
# Failed test 'bad time zone'
# at t/01_basic.t line 89.
# Looks like you failed 1 test of 21.
t/01_basic.t ................ Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/21 subtests
t/02_olson_abbreviations.t .. ok
t/03_local_floating.t ....... ok

Test Summary Report
-------------------
t/01_basic.t (Wstat: 256 Tests: 21 Failed: 1)
Failed test: 16
Non-zero exit status: 1
Files=3, Tests=28, 5 wallclock secs ( 0.09 usr 0.01 sys + 5.34 cusr 0.17 csys = 5.61 CPU)
Result: FAIL
Failed 1/3 test programs. 1/28 subtests failed.
make: *** [test_dynamic] エラー 255
ECARROLL/MooseX-Types-DateTime-ButMaintained-0.08.tar.gz
/usr/bin/make test -- NOT OK


では、テストコードから該当箇所を抜粋。


{
{
package Bar;
use Moose;

has time_zone => (
isa => "DateTime::TimeZone",
is => "rw",
coerce => 1,
);
}

my $tz = Bar->new( time_zone => "Africa/Timbuktu" )->time_zone;

isa_ok( $tz, "DateTime::TimeZone", "coerced string into time zone object" );

like( $tz->name, qr/^Africa/, "correct time zone" );

dies_ok { Bar->new( time_zone => "Space/TheMoon" ) } "bad time zone";
}


coerceまわりがおかしいっぽい。
では、coerceまわりのロジックをチェック。


our %coercions = (
DateTime => [
from Num, via { 'DateTime'->from_epoch( epoch => $_ ) }
, from HashRef, via { 'DateTime'->new( %$_ ) }
, from Now, via { 'DateTime'->now }
]

, "DateTime::Duration" => [
from Num, via { DateTime::Duration->new( seconds => $_ ) }
, from HashRef, via { DateTime::Duration->new( %$_ ) }
]

, "DateTime::TimeZone" => [
from Str, via {
# No abbreviation - assumed if we don't have a '/'
if ( m,/|floating|local, ) {
return DateTime::TimeZone->new( name => $_ );
}
# Abbreviation - assumed if we do have a '/'
# returns a DateTime::TimeZone::OffsetOnly
else {
my $offset = Olson::Abbreviations->new({ tz_abbreviation => $_ })->get_offset;
return DateTime::TimeZone->new( name => $offset );
}
}
]


, "DateTime::Locale" => [
from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext")
, via { DateTime::Locale->load($_->language_tag) }
, from Str, via { DateTime::Locale->load($_) }
]
);


おかしくね、これ。おかしいよ。
だって、dieするわけないよ。そりゃあテスト通りませんよね...

どうしてこうなった!どうしてこうなった!

しょうがないので、force installしましたとさ。おしまい。

2009-09-14 追記
0.09がリリース済みです。
無事にテストも通りましたよ!
good job!

Running make for E/EC/ECARROLL/MooseX-Types-DateTime-ButMaintained-0.09.tar.gz
Is already unwrapped into directory /home/azuma/.cpan/build/MooseX-Types-DateTime-ButMaintained-0.09

CPAN.pm: Going to build E/EC/ECARROLL/MooseX-Types-DateTime-ButMaintained-0.09.tar.gz

/usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=DateTime::TimeZone,0.96
Cannot determine perl version info from lib/MooseX/Types/DateTime/ButMaintained.pm
cp lib/MooseX/Types/DateTime/ButMaintained.pm blib/lib/MooseX/Types/DateTime/ButMaintained.pm
Manifying blib/man3/MooseX::Types::DateTime::ButMaintained.3pm
/usr/bin/make -- OK
Running make test
/usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=DateTime::TimeZone,0.96
Cannot determine perl version info from lib/MooseX/Types/DateTime/ButMaintained.pm
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/01_basic.t t/02_olson_abbreviations.t t/03_local_floating.t
t/01_basic.t ................ ok
t/02_olson_abbreviations.t .. ok
t/03_local_floating.t ....... ok
All tests successful.
Files=3, Tests=28, 3 wallclock secs ( 0.02 usr 0.01 sys + 2.23 cusr 0.08 csys = 2.34 CPU)
Result: PASS
/usr/bin/make test -- OK
Running make install
/usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=DateTime::TimeZone,0.96
Cannot determine perl version info from lib/MooseX/Types/DateTime/ButMaintained.pm
Installing /usr/local/share/perl/5.8.8/MooseX/Types/DateTime/ButMaintained.pm
Installing /usr/local/man/man3/MooseX::Types::DateTime::ButMaintained.3pm
Appending installation info to /usr/lib/perl/5.8/perllocal.pod
/usr/bin/make install -- OK

2009-06-22

[Perl]MooseX::Autouseというものをでっち上げてみた

SVNレポジトリ上のtrunkに置いておきました。poorで拙い"engrish"やら少なすぎるtest等など、遠慮なくダメ出ししてやって下さい程々に凹みますので;;

と、自虐はこの辺にしといて、そろそろまともにMooseなモジュールを組んでみたくて、やらかしました。MooseでAutouseしたかったんです。use HogeFugaとかいちいち書くのダルくなっただけですが。

こんな感じでの使い方を想定しています。

MyClass.pm



package MyClass;
use Moose;
with 'MooseX::Autouse';
no Moose;
1;
__END__


myscript.cgi



use MyClass;
use Data::Dumper;
my $c = MyClass->new;
my $dbi = $c->DBI->connect( qw( dbi:mysql:mydb:mydbhost user pass ) );
my $cgi = $c->CGI->new;
print $cgi->header( 'text/html' );
print '<html><body><pre>'. Dumper( $dbi ). '</pre></body></html>';


今改めて見直すと、本当にただMoose使いたかっただけなんだなあって思えますね><

2009-04-21

[Perl]MooseX::Alienで、なんでもMoose

MooseX::Alienを使うと、非MooseなモジュールもMoose化できるらしい。

package MooseX::Safarize;
use Data::Dumper;
use Moose;
extends 'WWW::Mechanize';
with 'MooseX::Alien';

sub BUILD {
my $self = shift;
my @arg = @_;
$self->agent_alias( 'Mac Safari' );
}

before get => sub {
my ( $self, $uri ) = @_;
warn "GET $uri";
};

after get => sub {
my $self = shift;
warn "Status: ". $self->status. " ". length( $self->content ). " bytes DLed.";
};

no Moose;

my $c = MooseX::Safarize->new( timeout => 2 );
print Dumper $c->agent;
$c->get( 'http://www.cpan.org/' );


結果。

$VAR1 = 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/85 (KHTML, like Gecko) Safari/85';
GET http://www.cpan.org/ at ./safarize.pl line 15.
Status: 200 5810 bytes DLed. at ./safarize.pl line 20.

[Perl]Mooseでコンストラクタの挙動を変える

BUILDメソッドを定義することで対応できる。

package MyCar;
use Data::Dumper;
use Moose;

has 'speed' => ( is => 'rw', isa => 'Int' );

sub BUILD {
my $self = shift;
$self->speed( 50 ) if !$self->speed;
}

no Moose;

my $super_car = MyCar->new( speed => 200 );
my $normal_car = MyCar->new;

print "=== Super Car ===\n". Dumper $super_car;
print "=== Normal Car ===\n". Dumper $normal_car;

結果

=== Super Car ===
$VAR1 = bless( {
'speed' => 200
}, 'MyCar' );
=== Normal Car ===
$VAR1 = bless( {
'speed' => 50
}, 'MyCar' );