From: Dave Rolsky Date: Thu, 24 Sep 2009 21:55:32 +0000 (-0500) Subject: Add a short section on MX modules X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0066613deeccc40e1fd0a6216c4f924a85901e59;p=gitmo%2Fmoose-presentations.git Add a short section on MX modules --- diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index 98e190a..bc2aeb1 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -3534,9 +3534,199 @@ Iterate til this passes all its tests
-

Part 8: A Tour of MooseX

+

Part 8: A Brief Tour of MooseX

+
+

Notable Moose Extensions on CPAN

+ + +
+ +
+

Already Mentioned Several

+ + +
+ +
+

MooseX::Declare

+ +
use MooseX::Declare;
+use 5.10.0; # for say
+
+class Person {
+    has greeting
+        => ( is => 'ro', isa => 'Str' );
+
+    method speak {
+        say $self->greeting;
+    }
+}
+
+ +
+

MooseX::Declare

+ + +
+ +
+

MooseX::StrictConstructor

+ + +
+ +
+

MooseX::StrictConstructor

+ +
package Person;
+
+use Moose;
+use MooseX::StrictConstructor;
+
+has name => ( is => 'ro' );
+
+Person->new
+    ( nane => 'Ringo Shiina' ); # kaboom
+
+ +
+

MooseX::Traits

+ + +
+ +
+

MooseX::Traits

+ +
package MyApp::Thingy;
+use Moose;
+
+with 'MooseX::Traits';
+
+my $thing =
+    MyApp::Thingy->new_with_traits
+        ( traits => [ 'Foo', 'Bar' ],
+          size   => 42 );
+
+ +
+

MooseX::Getopt

+ + +
+ +
+

MooseX::Getopt

+ +
package App::CLI;
+use Moose;
+
+with 'MooseX::Getopt';
+
+has file    =>
+    ( is => 'ro', required => 1 );
+has filters =>
+    ( is => 'ro', isa => 'Str' );
+
+sub run { ... }
+
+ +
+

MooseX::Getopt

+ + + +
#!/usr/bin/perl
+
+use App::CLI;
+
+App::CLI->new_with_options()->run();
+ +
$ myapp-cli \
+   --file foo \
+   --filters compress \
+   --filters sanitize
+
+ +
+

MooseX::Clone

+ +
package Person;
+
+use Moose;
+with 'MooseX::Clone';
+
+my $person = Person->new;
+my $clone  = $person->clone;
+
+ +
+

MooseX::NonMoose

+ + +
+ +
+

MooseX::Role::Parameterized

+ +
package HasCollection;
+use MooseX::Role::Parameterized;
+
+parameter type => ( isa     => 'Str',
+                    default => 'Item' );
+role {
+    my $p = shift;
+
+    my $type = 'ArrayRef[' . $p->type() . ']';
+    has collection =>
+        ( is  => 'ro',
+          isa => $type );
+};
+
+ +
+

MooseX::Role::Parameterized

+ +
package Person;
+
+use Moose;
+with HasCollection => { type => 'Int' };
+
+ +
+

Questions?

+
+

Part 9: Writing Moose Extensions