import moose website
[gitmo/moose-htdocs.git] / oscon / 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 => 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----
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 => 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----
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 # 34
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 $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----
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
373----
374Moose/Class::MOP
375have +5400
376tests and growing
377----
378Why test, when
379Moose already does.
380----
381More 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