public
Last active

  • Download Gist
Hailo-moose-to-mouse.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
diff --git a/Changes b/Changes
index a0cfc93..c19f1b7 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,20 @@
+0.20 Sun Feb 28 00:29:32 GMT 2010
+
+ - Use Mouse instead of Moose by default but depend on both of
+ them.
+
+ This saves about 8MB of resident memory bringing Hailo's memory
+ usage with SQLite from 28MB to 20MB. Startup time is also
+ reduced with the test suite running around 46% faster.
+
+ - Run tests with Moose and Mouse during `make test`
+
+ - Drop MouseX::Role::Strict / MooseX::Role::Strict. Spotted when
+ switching to Moose but mainly we just didn't care about using
+ it.
+
+ - Word tokenizer: Improve punctuation when words are split with '/'
+
0.19 Sat Feb 27 04:23:03 GMT 2010
- Move File::Slurp from 'requires' to 'test_requires'
diff --git a/MANIFEST b/MANIFEST
index 7c515b8..dc2c201 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -29,6 +28,7 @@ MANIFEST.SKIP
META.yml
README
script/hailo
+t/00_diag.t
t/01_compile.t
t/02_chat.t
t/03_sanity.t
diff --git a/Makefile.PL b/Makefile.PL
index f3700d1..0ad2861 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -21,14 +25,22 @@ resources ('Time::HiRes' => '0');
resources ('FindBin' => '0');
resources ('File::Spec::Functions' => '0');
+## Depend on Mouse or Moose, we can use either one
+# Mouse
+requires('Mouse' => '0.50_04');
+requires('MouseX::Types' => '0.05');
+requires('MouseX::Getopt' => '0.2601');
+# Moose
+requires('Moose' => '0.94');
+requires('MooseX::Types' => '0.21');
+requires('MooseX::StrictConstructor' => '0.08');
+requires('MooseX::Getopt' => '0.26');
+
# Hailo.pm
+requires ('Any::Moose' => '0.11');
requires ('autodie' => '2.08');
-requires ('Moose' => '0.94');
-requires ('Class::MOP' => '0.98');
requires ('Data::Section' => '0.100270');
requires ('File::CountLines' => '0.0.2');
-requires ('MooseX::Getopt' => '0.26');
-requires ('MooseX::Getopt::Dashes' => '0');
requires ('Getopt::Long::Descriptive' => '0.083');
requires ('IO::Interactive' => '0.0.6');
requires ('Module::Pluggable' => '3.9');
@@ -45,10 +57,6 @@ requires ('Template' => '2.22');
requires ('DBD::SQLite' => '1.29');
# everywhere
-requires ('MooseX::Role::Strict' => '0.03');
-requires ('MooseX::StrictConstructor' => '0.08');
-requires ('MooseX::Types' => '0.21');
-requires ('MooseX::Types::Moose' => '0.21');
requires ('namespace::clean' => '0.13');
# Pg/mysql: optional backends
@@ -70,6 +78,16 @@ author_requires('Test::Perl::Critic' => '1.02');
author_requires('Test::Pod' => '1.41');
author_requires('Test::Pod::Coverage' => '1.08');
author_requires('Test::Script' => '1.07');
-author_tests ('xt');
-
+auto_provides ();
WriteAll();
+
+package MY;
+
+sub test {
+ my $inherited = shift->SUPER::test(@_);
+
+ # Run tests with Moose and Mouse
+ $inherited =~ s/^test_dynamic :: pure_all\n\t(.*?)\n/test_dynamic :: pure_all\n\tANY_MOOSE=Mouse $1\n\tANY_MOOSE=Moose $1\n/m;
+
+ return $inherited;
+}
diff --git a/README b/README
index 64d86aa..f46920f 100644
--- a/README
+++ b/README
@@ -31,8 +31,8 @@ SYNOPSIS
DESCRIPTION
Hailo is a fast and lightweight markov engine intended to replace
- AI::MegaHAL. It has a lightweight Moose-based core with pluggable
- storage and tokenizer backends.
+ AI::MegaHAL. It has a Mouse (or Moose) based core with pluggable storage
+ and tokenizer backends.
It is similar to MegaHAL in functionality, the main differences (with
the default backends) being better scalability, drastically less memory
diff --git a/lib/Hailo.pm b/lib/Hailo.pm
index f1a9b6b..c1e8824 100644
--- a/lib/Hailo.pm
+++ b/lib/Hailo.pm
@@ -2,11 +2,14 @@ package Hailo;
use 5.010;
use autodie qw(open close);
-use Class::MOP;
-use Moose;
-use MooseX::StrictConstructor;
-use MooseX::Types::Moose qw/Int Str Bool HashRef/;
-use MooseX::Getopt;
+use Any::Moose;
+use Any::Moose 'X::Getopt';
+use Any::Moose 'X::Types::'.any_moose() => [qw/Int Str Bool HashRef/];
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use Module::Pluggable (
search_path => [ map { "Hailo::$_" } qw(Storage Tokenizer UI) ],
except => [
@@ -21,7 +24,7 @@ use namespace::clean -except => [ qw(meta plugins) ];
our $VERSION = '0.19';
-with qw(MooseX::Getopt::Dashes);
+with any_moose('X::Getopt::Dashes');
has help => (
traits => [qw(Getopt)],
@@ -264,7 +267,12 @@ sub _new_class {
die "Couldn't find a class name matching '$class' in plugins '@plugins'";
}
- eval { Class::MOP::load_class($pkg) };
+ if (Any::Moose::moose_is_preferred()) {
+ require Class::MOP;
+ eval { Class::MOP::load_class($pkg) };
+ } else {
+ eval qq[require $pkg];
+ }
die $@ if $@;
return $pkg->new(%$args);
@@ -589,8 +598,8 @@ command-line invocation.
=head1 DESCRIPTION
Hailo is a fast and lightweight markov engine intended to replace
-L<AI::MegaHAL|AI::MegaHAL>. It has a lightweight L<Moose|Moose>-based core
-with pluggable L<storage|Hailo::Role::Storage> and
+L<AI::MegaHAL|AI::MegaHAL>. It has a L<Mouse|Mouse> (or L<Moose|Moose>)
+based core with pluggable L<storage|Hailo::Role::Storage> and
L<tokenizer|Hailo::Role::Tokenizer> backends.
It is similar to MegaHAL in functionality, the main differences (with the
diff --git a/lib/Hailo/Role/Arguments.pm b/lib/Hailo/Role/Arguments.pm
index 903b8be..45de217 100644
--- a/lib/Hailo/Role/Arguments.pm
+++ b/lib/Hailo/Role/Arguments.pm
@@ -1,7 +1,7 @@
package Hailo::Role::Arguments;
use 5.010;
-use MooseX::Role::Strict;
-use MooseX::Types::Moose qw/HashRef/;
+use Any::Moose '::Role';
+use Any::Moose 'X::Types::'.any_moose() => [qw/HashRef/];
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Role/Storage.pm b/lib/Hailo/Role/Storage.pm
index cf999d4..9518620 100644
--- a/lib/Hailo/Role/Storage.pm
+++ b/lib/Hailo/Role/Storage.pm
@@ -1,7 +1,7 @@
package Hailo::Role::Storage;
use 5.010;
-use MooseX::Role::Strict;
-use MooseX::Types::Moose qw<Str Int>;
+use Any::Moose '::Role';
+use Any::Moose 'X::Types::'.any_moose() => [qw/Str Int/];
use List::Util qw<min>;
use namespace::clean -except => 'meta';
diff --git a/lib/Hailo/Role/Tokenizer.pm b/lib/Hailo/Role/Tokenizer.pm
index c2537ce..63ab3a4 100644
--- a/lib/Hailo/Role/Tokenizer.pm
+++ b/lib/Hailo/Role/Tokenizer.pm
@@ -1,6 +1,6 @@
package Hailo::Role::Tokenizer;
use 5.010;
-use MooseX::Role::Strict;
+use Any::Moose '::Role';
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Role/UI.pm b/lib/Hailo/Role/UI.pm
index bad33f7..4aa872f 100644
--- a/lib/Hailo/Role/UI.pm
+++ b/lib/Hailo/Role/UI.pm
@@ -1,6 +1,6 @@
package Hailo::Role::UI;
use 5.010;
-use MooseX::Role::Strict;
+use Any::Moose '::Role';
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Storage/DBD.pm b/lib/Hailo/Storage/DBD.pm
index 48cc551..ec78928 100644
--- a/lib/Hailo/Storage/DBD.pm
+++ b/lib/Hailo/Storage/DBD.pm
@@ -1,8 +1,12 @@
package Hailo::Storage::DBD;
use 5.010;
-use Moose;
-use MooseX::StrictConstructor;
-use MooseX::Types::Moose qw<ArrayRef HashRef Int Str Bool>;
+use Any::Moose;
+use Any::Moose 'X::Types::'.any_moose() => [qw<ArrayRef HashRef Int Str Bool>];
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use DBI;
use List::Util qw<first shuffle>;
use List::MoreUtils qw<uniq>;
diff --git a/lib/Hailo/Storage/DBD/Pg.pm b/lib/Hailo/Storage/DBD/Pg.pm
index ab571a0..6d28247 100644
--- a/lib/Hailo/Storage/DBD/Pg.pm
+++ b/lib/Hailo/Storage/DBD/Pg.pm
@@ -1,7 +1,11 @@
package Hailo::Storage::DBD::Pg;
use 5.010;
-use Moose;
-use MooseX::StrictConstructor;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Storage/DBD/SQLite.pm b/lib/Hailo/Storage/DBD/SQLite.pm
index 8c90718..73ff75e 100644
--- a/lib/Hailo/Storage/DBD/SQLite.pm
+++ b/lib/Hailo/Storage/DBD/SQLite.pm
@@ -1,7 +1,11 @@
package Hailo::Storage::DBD::SQLite;
use 5.010;
-use Moose;
-use MooseX::StrictConstructor;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Storage/DBD/mysql.pm b/lib/Hailo/Storage/DBD/mysql.pm
index 66ea7d8..68e6bbf 100644
--- a/lib/Hailo/Storage/DBD/mysql.pm
+++ b/lib/Hailo/Storage/DBD/mysql.pm
@@ -1,7 +1,11 @@
package Hailo::Storage::DBD::mysql;
use 5.010;
-use Moose;
-use MooseX::StrictConstructor;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use List::MoreUtils qw< all >;
use namespace::clean -except => 'meta';
diff --git a/lib/Hailo/Tokenizer/Chars.pm b/lib/Hailo/Tokenizer/Chars.pm
index 153886b..e8eb7a9 100644
--- a/lib/Hailo/Tokenizer/Chars.pm
+++ b/lib/Hailo/Tokenizer/Chars.pm
@@ -1,6 +1,11 @@
package Hailo::Tokenizer::Chars;
use 5.010;
-use Moose;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/Tokenizer/Words.pm b/lib/Hailo/Tokenizer/Words.pm
index 0c1f4fc..8fa258d 100644
--- a/lib/Hailo/Tokenizer/Words.pm
+++ b/lib/Hailo/Tokenizer/Words.pm
@@ -1,8 +1,12 @@
package Hailo::Tokenizer::Words;
use 5.010;
use utf8;
-use Moose;
-use MooseX::StrictConstructor;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use namespace::clean -except => 'meta';
our $VERSION = '0.19';
diff --git a/lib/Hailo/UI/ReadLine.pm b/lib/Hailo/UI/ReadLine.pm
index 0549519..5d8e693 100644
--- a/lib/Hailo/UI/ReadLine.pm
+++ b/lib/Hailo/UI/ReadLine.pm
@@ -1,7 +1,11 @@
package Hailo::UI::ReadLine;
use 5.010;
-use Moose;
-use MooseX::StrictConstructor;
+use Any::Moose;
+BEGIN {
+ return unless Any::Moose::moose_is_preferred();
+ require MooseX::StrictConstructor;
+ MooseX::StrictConstructor->import;
+}
use Encode 'decode';
use Hailo;
use Term::ReadLine;
diff --git a/script/hailo b/script/hailo
index b6c6e6f..a072b9e 100755
--- a/script/hailo
+++ b/script/hailo
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use 5.010;
use open qw< :encoding(utf8) :std >;
-use Moose;
+use Any::Moose;
use Encode qw(decode);
use Hailo;
use namespace::clean -except => 'meta';
diff --git a/t/00_diag.t b/t/00_diag.t
new file mode 100644
index 0000000..4f7d3ee
--- /dev/null
+++ b/t/00_diag.t
@@ -0,0 +1,7 @@
+use strict;
+use Any::Moose;
+use Test::More tests => 1;
+
+my $m = any_moose();
+diag("Testing with $^X $] using $m for Moose");
+pass("Token test");
diff --git a/t/lib/Hailo/Test.pm b/t/lib/Hailo/Test.pm
index af47bcc..061eb12 100644
--- a/t/lib/Hailo/Test.pm
+++ b/t/lib/Hailo/Test.pm
@@ -1,7 +1,7 @@
package Hailo::Test;
use 5.010;
use autodie;
-use Moose;
+use Any::Moose;
use Hailo;
use Test::More;
use File::Spec::Functions qw(catfile);
@@ -124,7 +124,14 @@ sub spawn_storage {
);
if (exists $classes{$storage}) {
- eval { Class::MOP::load_class($classes{$storage}) };
+ my $pkg = $classes{$storage};
+ if (Any::Moose::moose_is_preferred()) {
+ require Class::MOP;
+ eval { Class::MOP::load_class($pkg) };
+ } else {
+ eval qq[require $pkg];
+ }
+
return if $@;
}
diff --git a/t/usage/options-and-usage.t b/t/usage/options-and-usage.t
index 79303b9..1996499 100644
--- a/t/usage/options-and-usage.t
+++ b/t/usage/options-and-usage.t
@@ -2,7 +2,7 @@ use 5.010;
use strict;
use warnings;
use List::MoreUtils qw(uniq);
-use Test::More tests => 39;
+use Test::More tests => 22;
use Test::Exception;
use Test::Output;
use Hailo;
@@ -93,12 +93,17 @@ is( sub {
# order
dies_ok { Hailo->new( order => undef ) } "undef order";
dies_ok { Hailo->new( order => "foo" ) } "Str order";
-for (my $i = 1; $i <= 10e10; $i += $i * 2) {
+for (my $i = 1; $i <= 10e2; $i += $i * 2) {
cmp_ok( Hailo->new( order => $i )->order, '==', $i, "The order is what we put in ($i)" );
}
# new
-dies_ok { Hailo->new( qw( a b c d ) ) } "Hailo dies on unknown arguments";
+SKIP: {
+ if (Any::Moose::mouse_is_preferred()) {
+ skip "Mouse doesn't have X::StrictConstructor", 1;
+ }
+ dies_ok { Hailo->new( qw( a b c d ) ) } "Hailo dies on unknown arguments";
+}
### Usage
diff --git a/utils/crunchbase-companies b/utils/crunchbase-companies
index 59196b6..0db64d3 100755
--- a/utils/crunchbase-companies
+++ b/utils/crunchbase-companies
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
use 5.010;
-use Moose;
+use Any::Moose;
use WWW::Mechanize;
=head1 NAME
diff --git a/utils/hailo-benchmark b/utils/hailo-benchmark
index c47dd74..1acc5c8 100755
--- a/utils/hailo-benchmark
+++ b/utils/hailo-benchmark
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use 5.010;
use lib 't/lib';
-use Moose;
+use Any::Moose;
use Hailo::Test;
use Benchmark qw(:all);
use File::Temp qw(tempfile tempdir);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.