diff --git a/sections/barewords.pod b/sections/barewords.pod index 787e5164..d2046208 100644 --- a/sections/barewords.pod +++ b/sections/barewords.pod @@ -115,14 +115,11 @@ Constants declared with the C pragma are usable as barewords: use constant NAME => 'Bucky'; use constant PASSWORD => '|38fish!head74|'; - ... - return unless $name eq NAME && $pass eq PASSWORD; =end programlisting -Note that these constants do I interpolate in double-quoted strings, for -example. +Note that these constants do I interpolate in double-quoted strings. X @@ -139,15 +136,6 @@ No matter how cautiously you code, barewords still produce ambiguous code. You can avoid most uses, but you will encounter several types of barewords in legacy code. -=head3 Bareword filehandles - -X - -Prior to lexical filehandles (L), all file and directory -handles used barewords. You can almost always safely rewrite this code to use -lexical filehandles; the exceptions are C, C, and C. -Fortunately, Perl's parser recognizes these. - =head3 Bareword function calls X @@ -162,8 +150,7 @@ accordingly. X -Along similar lines, old code may not take pains to quote the I of hash -pairs appropriately: +Some old code may not take pains to quote the I of hash pairs: =begin programlisting @@ -180,6 +167,15 @@ When neither the C nor C functions exist, Perl will interpret these barewords as strings. C will produce an error in this situation. +=head3 Bareword filehandles + +X + +Prior to lexical filehandles (L), all file and directory +handles used barewords. You can almost always safely rewrite this code to use +lexical filehandles; the exceptions are C, C, and C. +Fortunately, Perl's parser recognizes these. + =head3 Bareword sort functions X diff --git a/sections/indirect_objects.pod b/sections/indirect_objects.pod index b4bb0416..d64a6e77 100644 --- a/sections/indirect_objects.pod +++ b/sections/indirect_objects.pod @@ -69,7 +69,7 @@ variable I obvious, but it is not: =begin programlisting # DOES NOT WORK AS WRITTEN - say $config->{output} "This is a diagnostic message!"; + say $config->{output} 'Fun diagnostic message!'; =end programlisting @@ -87,7 +87,7 @@ subexpression which produces the intended invocant: =begin programlisting - say B<{>$config->{output}B<}> "This is a diagnostic message!"; + say B<{>$config->{output}B<}> 'Fun diagnostic message!'; =end programlisting diff --git a/sections/prototypes.pod b/sections/prototypes.pod index 665cb319..e08eb789 100644 --- a/sections/prototypes.pod +++ b/sections/prototypes.pod @@ -54,13 +54,11 @@ emulate: =begin screen - $ B - undef - # You can't emulate builtin function C's calling convention. + B + # undef; cannot emulate builtin C - $ B - undef - # Builtin function C has no prototype. + B + # undef; builtin C has no prototype =end screen @@ -111,7 +109,8 @@ incoming arguments: my @nums = 1 .. 10; - say "They're equal, whatever that means!" if numeric_equality @nums, 10; + say 'They're equal, whatever that means!' + if numeric_equality @nums, 10; =end programlisting @@ -197,9 +196,9 @@ and an optional description of the test: use Test::Exception; throws_ok - { my $not_an_object; $not_an_object->some_method() } - qr/Can't call method "some_method" on an undefined value/, - 'Calling a method on an undefined invocant should throw exception'; + { my $unobject; $unobject->yoink() } + qr/Can't call method "yoink" on an undefined/, + 'Method on undefined invocant should fail'; =end programlisting @@ -219,9 +218,9 @@ You may use C without taking advantage of the prototype: use Test::Exception; throws_okB<(> - B { my $not_an_object; $not_an_object->some_method() }B<,> - qr/Can't call method "some_method" on an undefined value/, - 'Calling a method on an undefined invocant should throw exception'B<)>; + B { my $unobject; $unobject->yoink() }B<,> + qr/Can't call method "yoink" on an undefined/, + 'Method on undefined invocant should fail' B<)>; =end programlisting @@ -235,7 +234,6 @@ with CN: sub length_sort ($$) { my ($left, $right) = @_; - return length($left) <=> length($right); } diff --git a/sections/tie.pod b/sections/tie.pod index 6909a389..217b2522 100644 --- a/sections/tie.pod +++ b/sections/tie.pod @@ -11,10 +11,10 @@ translates to a specific method call. X> X> -The C builtin originally allowed the use of hashes stored on disk, so that -Perl could access files larger than could easily fit in memory. The core module -C provides a similar system, and allows you to treat files as if -they were arrays. +The C builtin originally allowed you to use disk space as the backing +memory for hashes, so that Perl could access files larger than could easily fit +in memory. The core module C provides a similar system, and allows +you to treat files as if they were arrays. X> X> @@ -26,14 +26,14 @@ the core modules C, C, and C for specific details. Start by inheriting from one of those classes, then override any specific methods you need to modify. -=begin sidebar +=begin tip When Class and Package Names Collide If C weren't confusing enough, C, C, and C define the necessary interfaces to tie scalars, arrays, and hashes, but C, C, and C provide the default implementations. -=end sidebar +=end tip =head2 Tying Variables @@ -62,9 +62,11 @@ use C in a boolean context, however. =head2 Implementing Tied Variables To implement the class of a tied variable, inherit from a core module such as -C, then override the specific methods for the operations you -want to change. In the case of a tied scalar, these are likely C and -C, possibly C, and probably not C. +CN lacks its own F<.pm> file, so use +C to make it available.>, then override the specific methods for +the operations you want to change. In the case of a tied scalar, these are +likely C and C, possibly C, and probably not +C. You can create a class which logs all reads from and writes to a scalar with very little code: @@ -100,13 +102,6 @@ very little code: Assume that the C class method C takes a string and the number of frames up the call stack of which to report the location. -=begin tip Using C - -C lacks its own F<.pm> file; C to make it -available. - -=end tip - Within the C and C methods, C<$self> works as a blessed scalar. Assigning to that scalar reference changes the value of the scalar and reading from it returns its value. @@ -116,13 +111,13 @@ array and hash references, respectively. The C documentation explains the copious methods they support, as you can read or write multiple values from them, among other operations. -=begin sidebar +=begin tip Isn't C Fun? The C<-norequire> option prevents the C pragma from attempting to load a file for C, as that module is part of the file F. -=end sidebar +=end tip =head2 When to use Tied Variables