Commit | Line | Data |
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[ |
3 | Horizontal |
4 | Code Reuse |
5 | with |
6 | Møøse::Role |
7 | ---- |
8 | Stevan Little |
9 | stevan.little@iinteractive.com |
10 | http://www.iinteractive.com/moose |
11 | http://search.cpan.org/~stevan/ |
12 | ---- |
13 | Roles |
14 | ---- |
15 | ≠ |
16 | ---- |
17 | Classes |
18 | ---- |
19 | Roles |
20 | do /not/ |
21 | inherit. |
22 | ---- |
23 | Inheritance is |
24 | ↕ |
25 | vertical reuse. |
26 | ---- |
27 | Roles |
28 | compose. |
29 | ---- |
30 | Composition is |
31 | ↔ |
32 | horizontal reuse. |
33 | ---- |
34 | ... |
35 | ---- |
36 | When |
37 | to use |
38 | Roles |
39 | ---- |
40 | My general rule |
41 | of thumb is ... |
42 | ---- |
43 | s/MI/Roles/g |
44 | ---- |
45 | When |
46 | to /not/ use |
47 | Roles |
48 | ---- |
49 | When a class |
50 | just makes |
51 | more sense. |
52 | ---- |
53 | Roles are /not/ a |
54 | replacement for |
55 | inheritance. |
56 | ---- |
57 | How Roles |
58 | Work |
59 | ---- |
60 | Roles are |
61 | orphans. |
62 | ---- |
63 | Roles are |
64 | composed. |
65 | ---- |
66 | Local class |
67 | overrides role. |
68 | ---- |
69 | Role overrides |
70 | inherited class. |
71 | ---- |
72 | Roles can |
73 | conflict. |
74 | ---- |
75 | Method conflicts |
76 | must be |
77 | disambiguated. |
78 | ---- |
79 | Attribute conflicts |
80 | cannot be |
81 | disambiguated. |
82 | ---- |
83 | How |
84 | to use |
85 | Roles |
86 | ---- |
87 | package My::Role; |
88 | use Moose::Role; |
89 | |
90 | has my_attr => (is => 'rw'); |
91 | |
92 | requires 'a_method'; |
93 | |
94 | sub my_method { ... } |
95 | ---- |
96 | package My::Class; |
97 | use Moose; |
98 | |
99 | with 'My::Role'; |
100 | |
101 | sub a_method { ... } |
102 | ---- |
103 | my $o = My::Class->new( |
104 | my_attr => '...' |
105 | ); |
106 | |
107 | $o->my_method(); |
108 | ---- |
109 | Role |
110 | Examples |
111 | ---- |
112 | Behavior |
113 | Reuse |
114 | ---- |
115 | package My::App::Conversions; |
116 | use Moose::Role; |
117 | |
118 | sub decimal_to_percentage { ... } |
119 | sub percentage_to_decimal { ... } |
120 | ---- |
121 | Attribute |
122 | Reuse |
123 | ---- |
124 | package My::App::WithDBICSchema; |
125 | use Moose::Role; |
126 | |
127 | has 'schema' => ( |
128 | is => 'ro', |
129 | isa => 'DBIx::Class::Schema', |
130 | lazy => 1, |
131 | default => sub { |
132 | My::App::DB->connect(...) |
133 | } |
134 | ); |
135 | ---- |
136 | Abstract |
137 | Interfaces |
138 | ---- |
139 | package My::App::Iterator::Abstract; |
140 | use Moose::Role; |
141 | |
142 | requires 'has_next'; |
143 | requires 'next'; |
144 | requires 'peek'; |
145 | ---- |
146 | Partial |
147 | “Classes” |
148 | ---- |
149 | package My::App::Report::Base; |
150 | use Moose::Role; |
151 | |
152 | requires 'calculate'; |
153 | |
154 | sub run { |
155 | my $self = shift; |
156 | $self->setup; |
157 | $self->calculate; |
158 | $self->teardown; |
159 | } |
160 | |
161 | sub setup { ... } |
162 | sub teardown { ... } |
163 | ---- |
164 | Modules |
165 | which use |
166 | Roles |
167 | ---- |
168 | MooseX::Getopt |
169 | ---- |
170 | package My::App; |
171 | use Moose; |
172 | |
173 | with 'MooseX::Getopt'; |
174 | |
175 | has 'foo' => (is => 'rw', isa => 'Int'); |
176 | |
177 | sub run { ... } |
178 | |
179 | package main; |
180 | My::App->new_with_options->run |
181 | ---- |
182 | stevan>./my_app.pl --foo 10 |
183 | ---- |
184 | MooseX::Storage |
185 | ---- |
186 | MooseX::AttributeHelpers |
187 | ---- |
188 | Thank You |
189 | for coming. |
190 | ---- |
191 | And always |
192 | remember ... |
193 | ---- |
194 | Roles |
195 | ≠ |
196 | Classes |
197 | ]]></html:textarea> |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | <deck flex="1" id="deck"> |
210 | |
211 | <vbox flex="1" |
212 | onmousemove="Presentation.onMouseMoveOnCanvas(event);"> |
213 | <toolbox id="canvasToolbar"> |
214 | <toolbar> |
215 | <toolbarbutton oncommand="Presentation.home()" label="|<<" |
216 | observes="canBack"/> |
217 | <toolbarbutton oncommand="Presentation.back()" label="<" |
218 | observes="canBack"/> |
219 | <toolbarbutton oncommand="Presentation.forward()" label=">" |
220 | observes="canForward"/> |
221 | <toolbarbutton oncommand="Presentation.end()" label=">>|" |
222 | observes="canForward"/> |
223 | <toolbarseparator/> |
224 | <hbox align="center"> |
225 | <textbox id="current_page" size="4" |
226 | oninput="if (this.value) Presentation.showPage(parseInt(this.value)-1);"/> |
227 | <description value="/"/> |
228 | <description id="max_page"/> |
229 | </hbox> |
230 | <toolbarseparator/> |
231 | <vbox flex="2"> |
232 | <spacer flex="1"/> |
233 | <scrollbar id="scroller" |
234 | align="center" orient="horizontal" |
235 | oncommand="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));" |
236 | onclick="Presentation.showPage(parseInt(event.target.getAttribute('curpos')));" |
237 | onmousedown="Presentation.onScrollerDragStart();" |
238 | onmousemove="Presentation.onScrollerDragMove();" |
239 | onmouseup="Presentation.onScrollerDragDrop();"/> |
240 | <spacer flex="1"/> |
241 | </vbox> |
242 | <toolbarseparator/> |
243 | <spacer flex="1"/> |
244 | <toolbarseparator/> |
245 | <toolbarbutton id="toggleEva" label="Eva" |
246 | type="checkbox" |
247 | autoCheck="false" |
248 | oncommand="Presentation.toggleEvaMode();"/> |
249 | <toolbarseparator/> |
250 | <toolbarbutton label="Edit" |
251 | oncommand="Presentation.toggleEditMode();"/> |
252 | <toolbarbutton oncommand="Presentation.reload();" label="Reload"/> |
253 | </toolbar> |
254 | </toolbox> |
255 | <vbox flex="1" id="canvas" |
256 | onclick="Presentation.onPresentationClick(event);"> |
257 | <spacer flex="1"/> |
258 | <hbox flex="1"> |
259 | <spacer flex="1"/> |
260 | <vbox id="content"/> |
261 | <spacer flex="1"/> |
262 | </hbox> |
263 | <spacer flex="1"/> |
264 | </vbox> |
265 | </vbox> |
266 | |
267 | |
268 | <vbox flex="1" id="edit"> |
269 | <toolbox> |
270 | <toolbar> |
271 | <toolbarbutton label="New Page" |
272 | oncommand="Presentation.addPage()"/> |
273 | <spacer flex="1"/> |
274 | <toolbarseparator/> |
275 | <toolbarbutton label="View" |
276 | oncommand="Presentation.toggleEditMode();"/> |
277 | <toolbarbutton oncommand="Presentation.reload();" label="Reload"/> |
278 | </toolbar> |
279 | </toolbox> |
280 | <textbox id="textField" flex="1" multiline="true" |
281 | oninput="Presentation.onEdit()"/> |
282 | <hbox collapsed="true"> |
283 | <iframe id="dataLoader" onload="if (window.Presentation) Presentation.onDataLoad();"/> |
284 | </hbox> |
285 | </vbox> |
286 | |
287 | </deck> |
288 | |
289 | |
290 | <broadcasterset> |
291 | <broadcaster id="canBack"/> |
292 | <broadcaster id="canForward"/> |
293 | </broadcasterset> |
294 | |
295 | <commandset> |
296 | <command id="cmd_forward" |
297 | oncommand="if (Presentation.isPresentationMode) Presentation.forward();"/> |
298 | <command id="cmd_back" |
299 | oncommand="if (Presentation.isPresentationMode) Presentation.back();"/> |
300 | <command id="cmd_home" |
301 | oncommand="if (Presentation.isPresentationMode) Presentation.home();"/> |
302 | <command id="cmd_end" |
303 | oncommand="if (Presentation.isPresentationMode) Presentation.end();"/> |
304 | </commandset> |
305 | <keyset> |
306 | <key keycode="VK_ENTER" command="cmd_forward"/> |
307 | <key keycode="VK_RETURN" command="cmd_forward"/> |
308 | <key keycode="VK_PAGE_DOWN" command="cmd_forward"/> |
309 | <key keycode="VK_RIGHT" command="cmd_forward"/> |
310 | <key keycode="VK_DOWN" command="cmd_forward"/> |
311 | <!-- key keycode="VK_BACK_SPACE" command="cmd_back"/--> |
312 | <key keycode="VK_PAGE_UP" command="cmd_back"/> |
313 | <!-- <key keycode="VK_BACK_UP" command="cmd_back"/>--> |
314 | <!-- <key keycode="VK_BACK_LEFT" command="cmd_back"/>--> |
315 | <key keycode="VK_HOME" command="cmd_home"/> |
316 | <key keycode="VK_END" command="cmd_end"/> |
317 | <key key="n" modifiers="accel" oncommand="Presentation.addPage();"/> |
318 | <key key="r" modifiers="accel" oncommand="window.location.reload();"/> |
319 | <key key="e" modifiers="accel" oncommand="Presentation.toggleEditMode();"/> |
320 | <key key="a" modifiers="accel" oncommand="Presentation.toggleEvaMode();"/> |
321 | </keyset> |
322 | |
323 | |
324 | <script src="takahashi.js" type="application/x-javascript" /> |
325 | </page> |
326 | <!-- ***** BEGIN LICENSE BLOCK ***** |
327 | - Version: MPL 1.1 |
328 | - |
329 | - The contents of this file are subject to the Mozilla Public License Version |
330 | - 1.1 (the "License"); you may not use this file except in compliance with |
331 | - the License. You may obtain a copy of the License at |
332 | - http://www.mozilla.org/MPL/ |
333 | - |
334 | - Software distributed under the License is distributed on an "AS IS" basis, |
335 | - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
336 | - for the specific language governing rights and limitations under the |
337 | - License. |
338 | - |
339 | - The Original Code is the Takahashi-Method-based Presentation Tool in XUL. |
340 | - |
341 | - The Initial Developer of the Original Code is SHIMODA Hiroshi. |
342 | - Portions created by the Initial Developer are Copyright (C) 2005 |
343 | - the Initial Developer. All Rights Reserved. |
344 | - |
345 | - Contributor(s): SHIMODA Hiroshi <piro@p.club.ne.jp> |
346 | - |
347 | - ***** END LICENSE BLOCK ***** --> |
348 | |
349 | |