9e5a5b7c1fb40cbab8df7ae092e6df7110610f53
[gitmo/moose-website.git] / oscon / moose.xul
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[
3 Moose
4 ----
5 A Postmodern
6 Object System
7 for Perl 5
8 ----
9 Stevan Little
10 stevan@cpan.org
11 http://moose.perl.org/
12 ----
13 What is
14 Moose?
15 ----
16 What is
17 Class::MOP?
18 ----
19 What is
20 a MOP??
21 ----
22 Meta
23 Object
24 Protocol
25 ----
26 CLOS
27 ----
28 20 year old
29 LISP
30 technology
31 ----
32 Formalization
33 of the
34 object system
35 ----
36 How
37 classes
38 work
39 ----
40 How
41 methods
42 work
43 ----
44 How objects
45 are created
46 ... etc.
47 ----
48 Class::MOP
49 is CLOS for
50 Perl 5
51 ----
52 Class::MOP
53 is a
54 formalization
55 of Perl 5 OO
56 ----
57 Clarity &
58 Structure
59 ----
60 Class::MOP is
61 a platform for
62 ----
63 Moose
64 ----
65   package Person;
66   use Moose;
67
68   has name => (is => 'rw');
69   has age  => (is => 'rw');
70
71   1;
72 ----
73 turns on
74 strict &
75 warnings
76 ----
77 Moose::Object
78 in the @ISA
79 ----
80 `has` creates
81 accessor
82 called 'name'
83 ----
84 `has` creates
85 accessor
86 called 'age'
87 ----
88 *lots*
89 of class
90 metadata
91 ----
92   package Person;
93   use Moose;
94
95   has name => (is => 'rw');
96   has age  => (is => 'rw');
97
98   1;
99 ----
100 Types
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 ----
117 Custom
118 Types
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 => 34
136       )
137   ); 
138 ----
139   my $me = Person->new; # BOOM! name is required
140 ----
141   my $me = Person->new(
142       name => 'Stevan',
143       age  => 34
144   ); # BOOM! age should be DateTime::Duration
145 ----
146 Coercions
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  => 34
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 => 34, months => 11 }
187   );
188 ----
189   my $me = Person->new(
190       name => 'Stevan',
191       age  => { years => 34, months => 11 }
192   );
193   
194   $me->name # 'Stevan'
195   $me->age  # DateTime::Duration object 
196 ----
197   $me->name('Xoe');
198   
199   $me->age(11);
200   
201   $me->age({ years => 11, months => 8 }); 
202   
203   $me->age(DateTime::Duration->new({ 
204       years  => 11, 
205       months => 8 
206   })); 
207 ----
208 Delegation
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 # 34
224 ----
225 Unconventional
226 Delegation
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 $oscon = Conference->new(
243       attendees => [ $me, @all_you_guys ]
244   );
245   
246   $oscon->number_of_attendees; # lots of people
247   $oscon->add_attendee($some_slacker); # add a late comer
248 ----
249 Method 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 ----
269 Roles
270 ----
271
272 ----
273 Classes
274 ----
275 Roles
276 do /not/
277 inherit.
278 ----
279 Inheritance is
280
281 vertical reuse.
282 ----
283 Roles
284 compose.
285 ----
286 Composition is
287
288 horizontal reuse.
289 ----
290 ...
291 ----
292 When
293 to use
294 Roles
295 ----
296 My general rule 
297 of thumb is ...
298 ----
299 s/MI/Roles/g
300 ----
301 When 
302 to /not/ use 
303 Roles
304 ----
305 When a class 
306 just makes 
307 more sense.
308 ----
309 Roles are /not/ a
310 replacement for
311 inheritance.
312 ----
313 How Roles 
314 Work
315 ----
316 Roles are
317 orphans.
318 ----
319 Roles are 
320 composed.
321 ----
322 Local class
323 overrides role.
324 ----
325 Role overrides 
326 inherited class.
327 ----
328 Roles can 
329 conflict.
330 ----
331 Method conflicts
332 must be 
333 disambiguated.
334 ----
335 Attribute conflicts
336 cannot be 
337 disambiguated.
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 ----
366 Conclusion
367 ----
368 Moose code is shorter
369 ----
370 less code == less bugs
371 ----
372 Less testing
373 ----
374 Moose/Class::MOP 
375 have +5400 
376 tests and growing
377 ----
378 Why test, when 
379 Moose already does.
380 ----
381 More Readable
382 ----
383 ]]></html:textarea>
384
385 <deck flex="1" id="deck">
386
387 <vbox flex="1"
388         onmousemove="Presentation.onMouseMoveOnCanvas(event);">
389         <toolbox id="canvasToolbar">
390                 <toolbar>
391                         <toolbarbutton oncommand="Presentation.home()" label="|&lt;&lt;"
392                                 observes="canBack"/>
393                         <toolbarbutton oncommand="Presentation.back()" label="&lt;"
394                                 observes="canBack"/>
395                         <toolbarbutton oncommand="Presentation.forward()" label="&gt;"
396                                 observes="canForward"/>
397                         <toolbarbutton oncommand="Presentation.end()" label="&gt;&gt;|"
398                                 observes="canForward"/>
399                         <toolbarseparator/>
400                         <hbox align="center">
401                                 <textbox id="current_page" size="4"
402                                         oninput="if (this.value) Presentation.showPage(parseInt(this.value)-1);"/>
403                                 <description value="/"/>
404                                 <description id="max_page"/>
405                         </hbox>
406                         <toolbarseparator/>
407                         <vbox flex="2">
408                                 <spacer flex="1"/>
409                                 <scrollbar id="scroller"
410                                         align="center" orient="horizontal"
411                                         oncommand="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
412                                         onclick="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));"
413                                         onmousedown="Presentation.onScrollerDragStart();"
414                                         onmousemove="Presentation.onScrollerDragMove();"
415                                         onmouseup="Presentation.onScrollerDragDrop();"/>
416                                 <spacer flex="1"/>
417                         </vbox>
418                         <toolbarseparator/>
419                         <spacer flex="1"/>
420                         <toolbarseparator/>
421                         <toolbarbutton id="toggleEva" label="Eva"
422                                 type="checkbox"
423                                 autoCheck="false"
424                                 oncommand="Presentation.toggleEvaMode();"/>
425                         <toolbarseparator/>
426                         <toolbarbutton label="Edit"
427                                 oncommand="Presentation.toggleEditMode();"/>
428                         <toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
429                 </toolbar>
430         </toolbox>
431         <vbox flex="1" id="canvas"
432                 onclick="Presentation.onPresentationClick(event);">
433                 <spacer flex="1"/>
434                 <hbox flex="1">
435                         <spacer flex="1"/>
436                         <vbox id="content"/>
437                         <spacer flex="1"/>
438                 </hbox>
439                 <spacer flex="1"/>
440         </vbox>
441 </vbox>
442
443
444 <vbox flex="1" id="edit">
445         <toolbox>
446                 <toolbar>
447                         <toolbarbutton label="New Page"
448                                 oncommand="Presentation.addPage()"/>
449                         <spacer flex="1"/>
450                         <toolbarseparator/>
451                         <toolbarbutton label="View"
452                                 oncommand="Presentation.toggleEditMode();"/>
453                         <toolbarbutton oncommand="Presentation.reload();" label="Reload"/>
454                 </toolbar>
455         </toolbox>
456         <textbox id="textField" flex="1" multiline="true"
457                 oninput="Presentation.onEdit()"/>
458         <hbox collapsed="true">
459                 <iframe id="dataLoader" onload="if (window.Presentation) Presentation.onDataLoad();"/>
460         </hbox>
461 </vbox>
462
463 </deck>
464
465
466 <broadcasterset>
467         <broadcaster id="canBack"/>
468         <broadcaster id="canForward"/>
469 </broadcasterset>
470
471 <commandset>
472         <command id="cmd_forward"
473                 oncommand="if (Presentation.isPresentationMode) Presentation.forward();"/>
474         <command id="cmd_back"
475                 oncommand="if (Presentation.isPresentationMode) Presentation.back();"/>
476         <command id="cmd_home"
477                 oncommand="if (Presentation.isPresentationMode) Presentation.home();"/>
478         <command id="cmd_end"
479                 oncommand="if (Presentation.isPresentationMode) Presentation.end();"/>
480 </commandset>
481 <keyset>
482         <key keycode="VK_ENTER"      command="cmd_forward"/>
483         <key keycode="VK_RETURN"     command="cmd_forward"/>
484         <key keycode="VK_PAGE_DOWN"  command="cmd_forward"/>
485         <key keycode="VK_RIGHT"      command="cmd_forward"/>
486         <key keycode="VK_DOWN"       command="cmd_forward"/>
487         <!-- key keycode="VK_BACK_SPACE" command="cmd_back"/-->
488         <key keycode="VK_PAGE_UP"    command="cmd_back"/>
489         <!-- <key keycode="VK_BACK_UP"    command="cmd_back"/>-->
490         <!-- <key keycode="VK_BACK_LEFT"  command="cmd_back"/>-->
491         <key keycode="VK_HOME"       command="cmd_home"/>
492         <key keycode="VK_END"        command="cmd_end"/>
493         <key key="n" modifiers="accel" oncommand="Presentation.addPage();"/>
494         <key key="r" modifiers="accel" oncommand="window.location.reload();"/>
495         <key key="e" modifiers="accel" oncommand="Presentation.toggleEditMode();"/>
496         <key key="a" modifiers="accel" oncommand="Presentation.toggleEvaMode();"/>
497 </keyset>
498
499
500 <script src="takahashi.js" type="application/x-javascript" />
501 </page>
502 <!-- ***** BEGIN LICENSE BLOCK *****
503    - Version: MPL 1.1
504    -
505    - The contents of this file are subject to the Mozilla Public License Version
506    - 1.1 (the "License"); you may not use this file except in compliance with
507    - the License. You may obtain a copy of the License at
508    - http://www.mozilla.org/MPL/
509    -
510    - Software distributed under the License is distributed on an "AS IS" basis,
511    - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
512    - for the specific language governing rights and limitations under the
513    - License.
514    -
515    - The Original Code is the Takahashi-Method-based Presentation Tool in XUL.
516    -
517    - The Initial Developer of the Original Code is SHIMODA Hiroshi.
518    - Portions created by the Initial Developer are Copyright (C) 2005
519    - the Initial Developer. All Rights Reserved.
520    -
521    - Contributor(s): SHIMODA Hiroshi <piro@p.club.ne.jp>
522    -
523    - ***** END LICENSE BLOCK ***** -->
524
525