in reply to Perl code generation with PerlBean (continued)

Looking at this pice of code:
# Make the Circle area() method add it to the Circle PerlBean use PerlBean::Method; my $area_circle = PerlBean::Method->new( { method_name => 'area', body => <<EOF, my \$self = shift; return( 2 * 3.1415926 * \$self->get_radius() ); EOF } ); $circle->add_method( $area_circle );
If you use <<'EOF' you don't have to escape the scalars, which might be handy.

Secondly, doesn't your module generate the always-present my $self = shift?

Replies are listed 'Best First'.
Re: Re: Perl code generation with PerlBean (continued)
by zoccav (Sexton) on Nov 04, 2003 at 12:53 UTC
    Hi Jaap,

    If you use <<'EOF' you don't have to escape the scalars, which might be handy.
    I know. I used a lot of <<EOF in PerlBean itself to actually have the variables resolved in the text. E.g. for package names, subroutine names etc... Without giving it too much of a thought I simply went on with this in the tutorial.

    In this case too, the same change policy as the one I unfolded to Oren will apply.

    You can of course speed up development by fast-forwarding to section 10 of the tutorial :)

    Vincenzo
Re: Perl code generation with PerlBean (continued)
by zoccav (Sexton) on Nov 04, 2003 at 13:38 UTC
    Secondly, doesn't your module generate the always-present my $self = shift?
    • Remember that most methods are fully generated by PerlBean -with the my $self line. Typically, you'd write yourself as few as possible methods (the fun ones, and not the boring ones of course.)
    • You don't always need my $self. For instance for static methods.
    • It's not that much work to type yank a my $self = shift; line from another method.
    • As it's not too much work making this the default behavior for empty methods, I could. Then again, what would be the purpose of an empty method?
    Vincenzo