Skip to content

Commit

Permalink
Improved line and pagebreaking for chapter 9.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Dec 8, 2011
1 parent 337f583 commit 5e958de
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 188 deletions.
40 changes: 21 additions & 19 deletions sections/code_generation.pod
Expand Up @@ -62,15 +62,13 @@ others:
sub get_$methname
{
my \$self = shift;

return \$self->{$attrname};
}

sub set_$methname
{
my (\$self, \$value) = \@_;

\$self->{$attrname} = \$value;
\$self->{$attrname} = \$value;
}
END_ACCESSOR
}
Expand All @@ -79,10 +77,8 @@ others:

Woe to those who forget a backslash! Good luck convincing your syntax
highlighter what's happening! Worse yet, each invocation of string C<eval>
builds a new data structure representing the entire code. Compiling code isn't
free, either.

Even with its limitations, this technique is reasonably simple.
builds a new data structure representing the entire code, and compiling code
isn't free, either. Yet Even with its limitations, this technique is simple.

=head2 Parametric Closures

Expand All @@ -107,7 +103,6 @@ without requiring additional evaluation:
my $setter = sub
{
my ($self, $value) = @_;

$self->{$attrname} = $value;
};

Expand All @@ -130,11 +125,11 @@ Installing into symbol tables is reasonably easy, if ugly:
=begin programlisting

{
my ($getter, $setter) = generate_accessors( 'homecourt' );
my ($get, $set) = generate_accessors( 'pie' );

no strict 'refs';
*{ 'get_homecourt' } = $getter;
*{ 'set_homecourt' } = $setter;
*{ 'get_pie' } = $get;
*{ 'set_pie' } = $set;
}

=end programlisting
Expand Down Expand Up @@ -174,7 +169,7 @@ generate in a single line:
no strict 'refs';

*{ $methname } = sub {
# subtle bug: strict refs disabled in here too
# subtle bug: strict refs disabled here too
};
}

Expand All @@ -191,7 +186,8 @@ the contents of a variable, you can assign to the relevant symbol directly:

{
no warnings 'once';
(*get_homecourt, *set_homecourt) = generate_accessors( 'homecourt' );
(*get_pie, *set_pie) =
generate_accessors( 'pie' );
}

=end programlisting
Expand Down Expand Up @@ -242,7 +238,8 @@ The difference between writing:
{
for my $accessor (qw( age name weight ))
{
my ($get, $set) = make_accessors( $accessor );
my ($get, $set) =
make_accessors( $accessor );

no strict 'refs';
*{ 'get_' . $accessor } = $get;
Expand Down Expand Up @@ -316,7 +313,9 @@ To create a class:

use Class::MOP;

my $class = Class::MOP::Class->create( 'Monkey::Wrench' );
my $class = Class::MOP::Class->create(
'Monkey::Wrench'
);

=end programlisting

Expand All @@ -334,8 +333,8 @@ Add attributes and methods to this class when you create it:
(
attributes =>
[
Class::MOP::Attribute->new( '$material' ),
Class::MOP::Attribute->new( '$color' ),
Class::MOP::Attribute->new('$material'),
Class::MOP::Attribute->new('$color'),
]
methods =>
{
Expand All @@ -352,8 +351,11 @@ after you've created it:

=begin programlisting

$class->add_attribute( experience => Class::MOP::Attribute->new( '$xp' ) );
$class->add_method( bash_zombie => sub { ... } );
$class->add_attribute(
experience => Class::MOP::Attribute->new('$xp')
);

$class->add_method( bash_zombie => sub { ... } );

=end programlisting

Expand Down
4 changes: 2 additions & 2 deletions sections/distributions.pod
Expand Up @@ -105,8 +105,8 @@ X<cpanm>

=over 4

=item * C<App::cpanminus> provides almost configuration-free use of the public
CPAN. It provides the most common 90% of what a CPAN client needs.
=item * C<App::cpanminus> is a configuration-free CPAN client. It handles the
most common cases, uses little memory, and works quickly.

X<CPAN; C<App::perlbrew>>
X<perlbrew>
Expand Down

0 comments on commit 5e958de

Please sign in to comment.