import moose website
[gitmo/moose-htdocs.git] / PPW-2008 / moose.xul
CommitLineData
720accfe 1<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="chrome://global/skin/" type="text/css"?><?xml-stylesheet href="takahashi.css" type="text/css"?><page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="presentation" xmlns:html="http:/www.w3.org/1999/xhtml" orient="vertical" onkeypress="Presentation.onKeyPress(event);">
2<html:textarea id="builtinCode" style="visibility: collapse"><![CDATA[
3Moose
4----
5A Postmodern
6Object System
7for Perl 5
8----
9Stevan Little
10stevan@cpan.org
11http://moose.perl.org/
12----
13What is
14Moose?
15----
16What is
17Class::MOP?
18----
19What is
20a MOP??
21----
22Meta
23Object
24Protocol
25----
26CLOS
27----
2820 year old
29LISP
30technology
31----
32Formalization
33of the
34object system
35----
36How
37classes
38work
39----
40How
41methods
42work
43----
44How objects
45are created
46... etc.
47----
48Class::MOP
49is CLOS for
50Perl 5
51----
52Class::MOP
53is a
54formalization
55of Perl 5 OO
56----
57Clarity &
58Structure
59----
60Class::MOP is
61a platform for
62----
63Moose
64----
65 package Person;
66 use Moose;
67
68 has name => (is => 'rw');
69 has age => (is => 'rw');
70
71 1;
72----
73turns on
74strict &
75warnings
76----
77Moose::Object
78in the @ISA
79----
80`has` creates
81accessor
82called 'name'
83----
84`has` creates
85accessor
86called 'age'
87----
88*lots*
89of class
90metadata
91----
92 package Person;
93 use Moose;
94
95 has name => (is => 'rw');
96 has age => (is => 'rw');
97
98 1;
99----
100Types
101----
102 has name => (
103 is => 'rw',
104 isa => 'Str',
105 required => 1
106 );
107----
108 has age => (
109 is => 'rw',
110 isa => 'DateTime::Duration',
111 lazy => 1,
112 default => sub {
113 DateTime::Duration->new
114 }
115 );
116----
117Custom
118Types
119----
120 use Moose::Util::TypeConstraints;
121----
122 subtype 'NonEmptyStr'
123 => as 'Str'
124 => where { length $_ > 0 };
125----
126 has name => (
127 is => 'rw',
128 isa => 'NonEmptyStr',
129 required => 1
130 );
131----
132 my $me = Person->new(
133 name => 'Stevan',
134 age => DateTime::Duration->new(
135 years => 35
136 )
137 );
138----
139 my $me = Person->new; # BOOM! name is required
140----
141 my $me = Person->new(
142 name => 'Stevan',
143 age => 35
144 ); # BOOM! age should be DateTime::Duration
145----
146Coercions
147----
148 class_type 'DateTime::Duration';
149 coerce 'DateTime::Duration'
150 => from 'Int'
151 => via {
152 DateTime::Duration->new(
153 years => $_
154 )
155 };
156----
157 has age => (
158 is => 'rw',
159 isa => 'DateTime::Duration',
160 coerce => 1,
161 lazy => 1,
162 default => sub {
163 DateTime::Duration->new
164 }
165 );
166----
167 my $me = Person->new(
168 name => 'Stevan',
169 age => 35
170 );
171----
172 coerce 'DateTime::Duration'
173 => from 'Int'
174 => via {
175 DateTime::Duration->new(
176 years => $_
177 )
178 }
179 => from 'HashRef'
180 => via {
181 DateTime::Duration->new(%$_)
182 };
183----
184 my $me = Person->new(
185 name => 'Stevan',
186 age => { years => 35, months => 2 }
187 );
188----
189 my $me = Person->new(
190 name => 'Stevan',
191 age => { years => 35, months => 2 }
192 );
193
194 $me->name # 'Stevan'
195 $me->age # DateTime::Duration object
196----
197 my $xoe = Person->new(name => 'Xoe');
198
199 $xoe->age(11);
200
201 $xoe->age({ years => 11, months => 10 });
202
203 $xoe->age(DateTime::Duration->new({
204 years => 11,
205 months => 10
206 }));
207----
208Delegation
209----
210 has age => (
211 is => 'rw',
212 isa => 'DateTime::Duration',
213 coerce => 1,
214 lazy => 1,
215 default => sub {
216 DateTime::Duration->new
217 },
218 handles => {
219 'years_old' => 'years'
220 }
221 );
222----
223 $me->years_old # 35
224----
225Unconventional
226Delegation
227----
228 package Conference;
229 use Moose;
230 use MooseX::AttributeHelpers;
231
232 has attendees => (
233 metaclass => 'Collection::Array',
234 is => 'rw',
235 isa => 'ArrayRef[Person]',
236 provides => {
237 push => 'add_attendee',
238 count => 'number_of_attendees',
239 },
240 );
241----
242 my $ppw = Conference->new(
243 attendees => [ $me, @all_you_guys ]
244 );
245
246 $ppw->number_of_attendees; # lots of people
247 $ppw->add_attendee($some_slacker); # add a late comer
248----
249Method Modifiers
250----
251 before 'add_attendee' => sub {
252 my ($self, $attendee) = @_;
253 $self->setup_more_chairs(1);
254 };
255----
256 after 'add_attendee' => sub {
257 my ($self, $attendee) = @_;
258 $self->log("Attendee " . $attendee->name . " added");
259 };
260----
261 around 'add_attendee' => sub {
262 my ($next, $self, @args) = @_;
263 ...
264 my @return = $self->$next(@args);
265 ...
266 return @return;
267 };
268----
269Roles
270----
271≠
272----
273Classes
274----
275Roles
276do /not/
277inherit.
278----
279Inheritance is
280↕
281vertical reuse.
282----
283Roles
284compose.
285----
286Composition is
287↔
288horizontal reuse.
289----
290...
291----
292When
293to use
294Roles
295----
296My general rule
297of thumb is ...
298----
299s/MI/Roles/g
300----
301When
302to /not/ use
303Roles
304----
305When a class
306just makes
307more sense.
308----
309Roles are /not/ a
310replacement for
311inheritance.
312----
313How Roles
314Work
315----
316Roles are
317orphans.
318----
319Roles are
320composed.
321----
322Local class
323overrides role.
324----
325Role overrides
326inherited class.
327----
328Roles can
329conflict.
330----
331Method conflicts
332must be
333disambiguated.
334----
335Attribute conflicts
336cannot be
337disambiguated.
338----
339 package Age;
340 use Moose::Role;
341
342 # ... all that type stuff
343
344 has age => (
345 is => 'rw',
346 isa => 'DateTime::Duration',
347 coerce => 1,
348 lazy => 1,
349 default => sub {
350 DateTime::Duration->new
351 },
352 handles => {
353 'years_old' => 'years'
354 }
355 );
356
357 1;
358----
359 package Person;
360 use Moose;
361
362 with 'Age';
363
364 # ...
365----
366Conclusion
367----
368Moose code is shorter
369----
370less code == less bugs
371----
372Less testing
373needed
374----
375Moose/Class::MOP
376have +5400
377tests and growing
378----
379Why test, when
380Moose already does.
381----
382More Readable
383----
384Declarative code
385Descriptive code
386----
387The End
388----
389Questions?
390----
391]]></html:textarea>
392
393<deck flex="1" id="deck">
394
395<vbox flex="1"
396 onmousemove="Presentation.onMouseMoveOnCanvas(event);">
397 <toolbox id="canvasToolbar">
398 <toolbar>
399 <toolbarbutton oncommand="Presentation.home()" label="|&lt;&lt;"
400 observes="canBack"/>
401 <toolbarbutton oncommand="Presentation.back()" label="&lt;"
402 observes="canBack"/>
403 <toolbarbutton oncommand="Presentation.forward()" label="&gt;"
404 observes="canForward"/>
405 <toolbarbutton oncommand="Presentation.end()" label="&gt;&gt;|"
406 observes="canForward"/>
407 <toolbarseparator/>
408 <hbox align="center">
409 <textbox id="current_page" size="4"
410 oninput="if (this.value) Presentation.showPage(parseInt(this.value)-1);"/>
411 <description value="/"/>
412 <description id="max_page"/>
413 </hbox>
414 <toolbarseparator/>
415 <vbox flex="2">
416 <spacer flex="1"/>
417 <scrollbar id="scroller"
418 align="center" orient="horizontal"
419 oncommand="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
420 onclick="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
421 onmousedown="Presentation.onScrollerDragStart();"
422 onmousemove="Presentation.onScrollerDragMove();"
423 onmouseup="Presentation.onScrollerDragDrop();"/>
424 <spacer flex="1"/>
425 </vbox>
426 <toolbarseparator/>
427 <spacer flex="1"/>
428 <toolbarseparator/>
429 <toolbarbutton id="toggleEva" label="Eva"
430 type="checkbox"
431 autoCheck="false"
432 oncommand="Presentation.toggleEvaMode();"/>
433 <toolbarseparator/>
434 <toolbarbutton label="Edit"
435 oncommand="Presentation.toggleEditMode();"/>
436 <toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
437 </toolbar>
438 </toolbox>
439 <vbox flex="1" id="canvas"
440 onclick="Presentation.onPresentationClick(event);">
441 <spacer flex="1"/>
442 <hbox flex="1">
443 <spacer flex="1"/>
444 <vbox id="content"/>
445 <spacer flex="1"/>
446 </hbox>
447 <spacer flex="1"/>
448 </vbox>
449</vbox>
450
451
452<vbox flex="1" id="edit">
453 <toolbox>
454 <toolbar>
455 <toolbarbutton label="New Page"
456 oncommand="Presentation.addPage()"/>
457 <spacer flex="1"/>
458 <toolbarseparator/>
459 <toolbarbutton label="View"
460 oncommand="Presentation.toggleEditMode();"/>
461 <toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
462 </toolbar>
463 </toolbox>
464 <textbox id="textField" flex="1" multiline="true"
465 oninput="Presentation.onEdit()"/>
466 <hbox collapsed="true">
467 <iframe id="dataLoader" onload="if (window.Presentation) Presentation.onDataLoad();"/>
468 </hbox>
469</vbox>
470
471</deck>
472
473
474<broadcasterset>
475 <broadcaster id="canBack"/>
476 <broadcaster id="canForward"/>
477</broadcasterset>
478
479<commandset>
480 <command id="cmd_forward"
481 oncommand="if (Presentation.isPresentationMode) Presentation.forward();"/>
482 <command id="cmd_back"
483 oncommand="if (Presentation.isPresentationMode) Presentation.back();"/>
484 <command id="cmd_home"
485 oncommand="if (Presentation.isPresentationMode) Presentation.home();"/>
486 <command id="cmd_end"
487 oncommand="if (Presentation.isPresentationMode) Presentation.end();"/>
488</commandset>
489<keyset>
490 <key keycode="VK_ENTER" command="cmd_forward"/>
491 <key keycode="VK_RETURN" command="cmd_forward"/>
492 <key keycode="VK_PAGE_DOWN" command="cmd_forward"/>
493 <key keycode="VK_RIGHT" command="cmd_forward"/>
494 <key keycode="VK_DOWN" command="cmd_forward"/>
495 <!-- key keycode="VK_BACK_SPACE" command="cmd_back"/-->
496 <key keycode="VK_PAGE_UP" command="cmd_back"/>
497 <!-- <key keycode="VK_BACK_UP" command="cmd_back"/>-->
498 <!-- <key keycode="VK_BACK_LEFT" command="cmd_back"/>-->
499 <key keycode="VK_HOME" command="cmd_home"/>
500 <key keycode="VK_END" command="cmd_end"/>
501 <key key="n" modifiers="accel" oncommand="Presentation.addPage();"/>
502 <key key="r" modifiers="accel" oncommand="window.location.reload();"/>
503 <key key="e" modifiers="accel" oncommand="Presentation.toggleEditMode();"/>
504 <key key="a" modifiers="accel" oncommand="Presentation.toggleEvaMode();"/>
505</keyset>
506
507
508<script src="takahashi.js" type="application/x-javascript" />
509</page>
510<!-- ***** BEGIN LICENSE BLOCK *****
511 - Version: MPL 1.1
512 -
513 - The contents of this file are subject to the Mozilla Public License Version
514 - 1.1 (the "License"); you may not use this file except in compliance with
515 - the License. You may obtain a copy of the License at
516 - http://www.mozilla.org/MPL/
517 -
518 - Software distributed under the License is distributed on an "AS IS" basis,
519 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
520 - for the specific language governing rights and limitations under the
521 - License.
522 -
523 - The Original Code is the Takahashi-Method-based Presentation Tool in XUL.
524 -
525 - The Initial Developer of the Original Code is SHIMODA Hiroshi.
526 - Portions created by the Initial Developer are Copyright (C) 2005
527 - the Initial Developer. All Rights Reserved.
528 -
529 - Contributor(s): SHIMODA Hiroshi <piro@p.club.ne.jp>
530 -
531 - ***** END LICENSE BLOCK ***** -->
532
533