Object Oriented Perl

Free Download

Authors:

ISBN: 9781884777790, 1-884777-79-1

Size: 5 MB (5321904 bytes)

Pages: 510/510

File format:

Language:

Publishing Year:

Category: Tags: , ,

Damian Conway9781884777790, 1-884777-79-1

Conway’s Object Oriented Perl provides an invaluable guide to virtually every aspect of object-oriented programming in Perl.The most notable thing about Object Oriented Perl is Conway’s excellent perspective on object-oriented concepts and how they are implemented in Perl. This book does a remarkable job of cutting through traditional jargon and illustrating how basic object-oriented design techniques are handled in Perl. (A useful appendix attests to the author’s wide-ranging knowledge, with a comparison of Smalltalk, Eiffel, C++, and Java with Perl, including a summary of object-oriented syntax for each.) This book also features a truly excellent review of basic Perl syntax.Throughout this text, the author shows you the basics of solid object design (illustrated using classes that model music CDs). Basic concepts like inheritance and polymorphism get thorough and clear coverage. The book also points out common mistakes and provides many tips for navigating the powerful and flexible (yet sometimes tricky) nuances of using Perl objects. For instance, Conway shows how to achieve true data encapsulation in Perl (which generally allows calls across modules) as well as its natural support for generic programming techniques.He also pays special attention to popular object modules available from CPAN (like Class::MethodmakerK, which simplifies declaring classes) and discusses performance issues and the tradeoff between programming convenience and speed often faced by today’s Perl developer. Advanced chapters cover a number of techniques for adding persistence and invoking methods using multiple dispatching.Filled with syntactic tips and tricks, Object Oriented Perl is a sure bet for any programmer who wants to learn how to use Perl objects effectively

Table of contents :
contents……Page 7
foreword……Page 11
preface……Page 12
acknowledgments……Page 18
author online……Page 20
What you need to know first (An object orientation primer)……Page 21
1.1.1 Objects……Page 22
1.1.2 Classes……Page 23
1.1.3 Class attributes and methods……Page 24
1.1.4 Inheritance……Page 25
1.1.5 Polymorphism……Page 29
1.2.1 Interface vs. implementation……Page 33
1.2.2 Aggregation……Page 34
1.2.3 Genericity……Page 35
1.2.4 Persistence……Page 36
1.4 Where to find out more……Page 38
1.4.2 Websites……Page 39
1.5 Summary……Page 40
2.1.1 Scalars……Page 41
2.1.2 Arrays……Page 42
2.1.3 Hashes……Page 46
2.1.4 Subroutines……Page 48
2.1.5 References and referents……Page 57
2.1.6 Packages……Page 63
2.2.1 Modules……Page 71
2.2.2 Autoloading……Page 75
2.2.3 Closures……Page 76
2.2.4 Typeglobs……Page 79
2.3 The CPAN……Page 85
2.3.2 How to search the CPAN……Page 86
2.3.3 How to install modules from the CPAN……Page 87
2.4 Where to find out more……Page 88
2.4.2 Useful books……Page 89
2.4.4 The Perl Journal……Page 90
2.4.6 Newsgroups……Page 91
2.5 Summary……Page 92
3.1 Three little rules……Page 93
3.1.2 Rule 2: To create a method, write a subroutine……Page 94
3.1.3 Rule 3: To create an object, bless a referent……Page 96
3.2.1 The code……Page 100
3.2.2 Using the CD::Music class……Page 108
3.3.2 use strict and the -w flag……Page 109
3.3.3 Automating data member access……Page 111
3.3.4 Documenting a class……Page 114
3.4.1 Constructors……Page 116
3.4.2 Destructors……Page 126
3.5 The CD::Music class, compleat……Page 134
3.6 Summary……Page 137
4.1 What’s wrong with a hash?……Page 138
4.2 Blessing an array……Page 139
4.2.1 An array-specific example—iterators……Page 143
4.3.1 A pseudo what???……Page 146
4.3.2 Advantages of a pseudo-hash……Page 148
4.3.3 The worst of both worlds?……Page 149
4.3.4 Compile-time support for run-time performance……Page 150
4.3.5 Typed lexicals……Page 151
4.3.6 Yet another version of CD::Music……Page 152
4.4.1 Why not bless a scalar?……Page 155
4.4.2 An object-oriented password……Page 156
4.4.3 A bit-string class……Page 158
4.4.4 Where to find out more……Page 161
4.5 Summary……Page 162
5.1.1 The qr operator……Page 163
5.1.2 Why an object-oriented regular expression class?……Page 165
5.1.3 Designing a different regular expressions mechanism……Page 166
5.1.4 A closer look at the two classes……Page 168
5.2.1 So, how can a subroutine be an object?……Page 171
5.2.2 Why objectify a subroutine?……Page 173
5.2.3 A lexer object……Page 174
5.2.5 Where to find out more……Page 177
5.3 Blessing a typeglob……Page 178
5.3.1 Paging STDOUT……Page 179
5.3.2 A multiprocess pager class……Page 180
5.3.3 A threaded pager class……Page 184
5.4 Summary……Page 186
6.1.1 The @ISA array……Page 188
6.1.2 What inheritance means in Perl……Page 189
6.1.4 Constructors and inheritance……Page 191
6.1.5 Diamonds are forfended……Page 195
6.1.6 Destructors and inheritance……Page 196
6.2.1 The isa() method……Page 198
6.2.2 The can() method……Page 199
6.2.3 The UNIVERSAL package……Page 202
6.2.4 The SUPER pseudo-package……Page 203
6.2.5 Implementing abstract methods……Page 205
6.2.6 Naming attributes of derived classes……Page 206
6.2.7 The empty subclass test……Page 209
6.2.8 Inheritance and pseudo-hashes……Page 210
6.3.1 Applied Laziness……Page 213
6.3.2 Class data access revisited……Page 216
6.3.3 An alternative solution……Page 218
6.4 Where to find out more……Page 221
6.5 Summary……Page 222
7.1 Polymorphism in Perl……Page 223
7.1.2 Inheritance polymorphism……Page 224
7.2 Example: Polymorphic methods for the Lexer class……Page 225
7.3 The simple pretty-printer objectified……Page 228
7.4 Using interface polymorphism instead……Page 230
7.6 Summary……Page 232
8.1.1 Creating classes……Page 233
8.1.2 Attribute types……Page 235
8.1.3 Hierarchical class structures……Page 238
8.1.5 Inheritance and generated classes……Page 239
8.1.6 A full example—automating the CD::Music class……Page 240
8.2 The Class::MethodMaker module……Page 242
8.2.1 Constructors……Page 243
8.2.2 Scalar attributes……Page 244
8.2.3 Grouped scalar attributes……Page 245
8.2.5 Keylike attributes……Page 246
8.2.6 Nonscalar attributes……Page 247
8.2.8 Nested objects as attributes……Page 248
8.2.9 Subroutines as attributes……Page 251
8.2.10 Abstract methods……Page 252
8.2.12 A full example: reautomating the CD::Music class……Page 253
8.3 Where to find out more……Page 254
8.4 Summary……Page 255
9.1 A jacketing tie required……Page 256
9.1.1 Limitations of tie-ing……Page 257
9.2.1 Untie-ing a scalar……Page 258
9.2.2 A simple example……Page 259
9.2.3 Implementing a scalar using a nonscalar……Page 261
9.3 Tie-ing a hash……Page 263
9.3.1 Example: case-insensitive hashes……Page 265
9.4 Tie-ing an array……Page 269
9.4.1 Example: a base/codon array……Page 270
9.5 Tie-ing a filehandle……Page 276
9.5.1 An example: filtered filehandles……Page 277
9.6.1 Example: sorted hashes……Page 282
9.6.2 Another example: micro-tracked scalars……Page 284
9.7.1 A DNA class……Page 285
9.7.2 Object-oriented tied filehandles……Page 288
9.7.3 Blessing and tie-ing to the same package……Page 290
9.8 Where to find out more……Page 294
9.9 Summary……Page 295
10.1 The problem……Page 296
10.2 Perl’s operator overloading mechanism……Page 298
10.2.1 “Automagic” operators……Page 300
10.2.2 Fallback operations……Page 301
10.2.3 Specifying conversion operations……Page 302
10.3 Example: A Roman numerals class……Page 304
10.3.1 Creating class constants……Page 308
10.4 Circumventing undesired reference semantics……Page 311
10.5 The use and abuse of operators……Page 312
10.5.1 When to overload?……Page 314
10.7 Summary……Page 315
11.1 The perils of trust……Page 316
11.2 Encapsulation via closures……Page 317
11.2.1 A variation for the paranoid……Page 320
11.3.1 Name, rank, and serial number……Page 322
11.3.2 Controlled access……Page 324
11.3.4 A question of identity……Page 326
11.3.5 A variation for the truly paranoid……Page 327
11.4 Encapsulation via ties……Page 329
11.4.2 Constructing a securehash……Page 331
11.4.3 Declaring securehash entries……Page 332
11.4.4 Accessing securehash entries……Page 333
11.4.5 Iterating a securehash……Page 335
11.4.6 Ambiguous keys in a securehash……Page 336
11.4.7 Debugging a securehash……Page 339
11.4.8 “Fast” securehashes……Page 341
11.4.9 “Strict” securehashes……Page 343
11.4.10 The formal access rules……Page 344
11.6 Summary……Page 346
12.1 Why Perl doesn’t need special generic mechanisms……Page 347
12.2.1 Closures as generic methods……Page 349
12.2.2 Eval-ing generic classes……Page 354
12.3.1 The generic Tree class……Page 356
12.3.2 A specific node class……Page 359
12.3.3 Building related node classes……Page 362
12.3.4 Cleaning up the act: an abstract base class……Page 363
12.3.5 An unrelated node class……Page 364
12.3.6 Putting it all together……Page 368
12.3.7 A philosophical note……Page 369
12.5 Summary……Page 370
13.1 What is multiple dispatch?……Page 371
13.2 Multiple dispatch via single dispatch and cases……Page 373
13.3 Multiple dispatch via a table……Page 376
13.3.1 Determining the table initialization order……Page 379
13.3.2 Ordering problems……Page 380
13.4 Comparing the two approaches……Page 381
13.5 Dynamic dispatch tables……Page 383
13.5.1 No free lunch………Page 386
13.7 The Class::Multimethods module……Page 387
13.7.1 Identifying the nearest multimethod……Page 388
13.7.2 Finding the nearest multimethod……Page 389
13.7.3 Implications of breadth-first multimethod dispatch……Page 392
13.7.4 Handling resolution failure……Page 396
13.7.5 Defining multimethods outside their classes……Page 398
13.7.6 Multimethods as regular subroutines……Page 400
13.7.7 Nonclass types as parameters……Page 401
13.7.8 Last resort parameters……Page 402
13.7.9 Recursive multiple dispatch……Page 403
13.7.10 Debugging a multimethod……Page 404
13.10 Summary……Page 405
14.1 The ingredients……Page 407
14.1.1 Identity……Page 408
14.1.2 Encoding/serialization……Page 409
14.1.3 Storage……Page 412
14.1.4 Coordination……Page 417
14.2.1 Encoding objects……Page 418
14.2.2 Object-oriented encoding……Page 419
14.3.1 Class-specific persistence……Page 420
14.3.2 Some improvements……Page 424
14.3.3 Coarse-grained persistence for any data……Page 428
14.4 Fine-grained persistence……Page 432
14.4.1 Disk files as objects……Page 433
14.4.2 Memory-mapped files as objects……Page 436
14.4.3 Tied databases as objects……Page 438
14.4.4 Fine-grained persistence for any class……Page 441
14.4.5 Easier persistence through genericity……Page 444
14.5 Where to find out more……Page 447
14.6 Summary……Page 448
Quick reference guide……Page 449
B.1 Perl and Smalltalk……Page 458
B.1.3 Methods……Page 459
B.1.4 Encapsulation……Page 460
B.1.6 Polymorphism……Page 461
B.1.8 Comparative syntax……Page 462
B.2 Perl and C++……Page 463
B.2.2 Classes……Page 464
B.2.3 Methods……Page 465
B.2.7 Polymorphism……Page 466
B.2.8 Comparative syntax……Page 467
B.3.1 Objects……Page 469
B.3.3 Methods……Page 470
B.3.7 Polymorphism……Page 471
B.3.9 Comparative syntax……Page 472
B.4.2 Classes……Page 474
B.4.3 Methods……Page 475
B.4.6 Polymorphism……Page 476
B.4.9 Where to find out more……Page 477
glossary……Page 479
bibliography……Page 486
index……Page 488

Reviews

There are no reviews yet.

Be the first to review “Object Oriented Perl”
Shopping Cart
Scroll to Top