Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #47027] Documentation: BEGIN, END docs in wrong section

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

May 3, 2012, 6:50 PM

Post #1 of 6 (403 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section

On Tue Oct 30 08:01:32 2007, denis.howe [at] gmail wrote:
>
> This is a bug report for perl from denis.howe [at] gmail,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
>
> -----------------------------------------------------------------
>
> The section "BEGIN, CHECK, INIT and END" in the
> "perlmod" docs has nothing to do with modules and should
> be moved to the "perlsyn" "Compound Statements" section
> where any reasonable person would expect to find it.
>
> -----------------------------------------------------------------

Reviewing this older ticket tonight, I note that there was some
back-and-forth as to a better place to put documentation of these named
blocks: perlsyn, perlsub and perlcompile were all mentioned.

However, the facts that (a) no one ever submitted any patches for any of
these ideas; (b) the thread petered out over four years ago suggest that
we don't have a compelling reason to move this out of perlmod.

Do people agree with that argument? If so, we can put this ticket out
of its misery.

Thank you very much.
Jim Keenan

---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027


perlbug-followup at perl

May 3, 2012, 10:39 PM

Post #2 of 6 (401 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section [In reply to]

On Thu May 03 19:29:24 2012, perl.p5p [at] rjbs wrote:
> * James E Keenan via RT <perlbug-followup [at] perl> [2012-05-03T21:50:55]
> > Do people agree with that argument? If so, we can put this ticket out
> > of its misery.
>
> I agree.
>
I disagree. The BEGIN/END blocks are part of the language, they are not
exclusive to using the symbol table or to 'use'ing a .pm file. The
BEGIN/END blocks should go in perlsyn. Putting them in perlsub doesnt
seem right.


---
via perlbug: queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027


perlbug-followup at perl

May 4, 2012, 8:49 AM

Post #3 of 6 (403 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section [In reply to]

On Fri May 04 07:13:17 2012, denis.howe [at] gmail wrote:
> On 2007-10-30 at 08:01:32, denis.howe [at] gmail wrote:
>
> >> The section "BEGIN, CHECK, INIT and END" in the
> >> "perlmod" docs has nothing to do with modules and should
> >> be moved to the "perlsyn" "Compound Statements" section
> >> where any reasonable person would expect to find it.
>
> If I create a patch, what are the chances of it being accepted?

I don’t know; something like 80%, maybe? :-)


--

Father Chrysostomos


---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027


perlbug-followup at perl

May 4, 2012, 6:57 PM

Post #4 of 6 (393 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section [In reply to]

On Fri May 04 09:23:17 2012, tom christiansen wrote:
> That's not quite true.
>
> Things like UNITCHECK and END are used as per-module
> setup and cleanup code that are called implicitly; hence
> the all-caps. This makes for more robust module design
> that making people call mod_setup() and mod_cleanup()
> type functions, which they might forget to do.
>
> END works as a classwide destructor, just as DESTROY
> works as a per-object destructor.
>
> So I disagree that those functions have nothing to
> do with modules.

Although textbook usage of the BEGIN/END blocks is with modules, there
is no reason to only use them with modules. Here is an example of the
END block, no packages, no modules, no symbol table, no blessed objects.
______________________________________
use strict;
use warnings;
sub createHandle {
return int(rand(5999))+1;
}
sub destroyHandle{
my $handle = shift;
die "handle is invalid" if $handle > 6000 || $handle < 0;
print "handle destroyed\n";
}
my $newHandle = createHandle();
die "time to die";
END{
if($newHandle) {destroyHandle($newHandle);}
}
________________________________________
If I want to clean up resources in Perl on a die/croak, and don't want
to write a class, which is 1-3 (OOP ones) very challanging PODs (for a
beginner) which a user must read, the simplest thing is to use an END
block. An END block is much easier for a beginning Perl programmer to
use than making a package, writing a new sub (includes choosing whether
to bless a scalar, a hash, or an array, or more!), writing a DESTROY
sub, switch back to main package, and creating an instance of the class,
and repeat the previous steps half a dozen times. With END they can use
die without having to call a C-ish destructor sub before each die
statement in their code.

Sorry if this reply appears twice.

---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027


perlbug-followup at perl

May 6, 2012, 10:04 AM

Post #5 of 6 (393 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section [In reply to]

On Sun May 06 06:32:23 2012, rurban wrote:
> Any reasonable person is expected to find it the file where it was
> for the last 20 years or so.
Age is not a reason not to change or improve the PODs.

---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027


perlbug-followup at perl

May 8, 2012, 8:49 AM

Post #6 of 6 (399 views)
Permalink
[perl #47027] Documentation: BEGIN, END docs in wrong section [In reply to]

On Tue May 08 08:21:21 2012, dcmertens.perl [at] gmail wrote:
> I can have arbitrarily many BEGIN blocks in the same package, and they are
> called in the order that they are declared. I can only have one DESTROY
> subroutine in a given package, and only the last executed definition is
> used when I call it.

#!perl

use 5.15.9;

sub MODIFY_CODE_ATTRIBUTES { $_[1](); undef *DESTROY; () }

warn "run time";

sub DESTROY :foo { warn "hello" }
sub DESTROY :bar { warn "good bye" }
sub DESTROY :baz { warn "hello again" }

__END__
hello at - line 9.
good bye at - line 10.
hello again at - line 11.
run time at - line 7.


> This makes named blocks just that: blocks, not
> subroutines.

They might be special, but they are still subroutines. You can goto&
out of them. You can return from them.

#!perl

DESTROY { warn "destroy" }
BEGIN { warn "begin 1" }
BEGIN { goto &DESTROY }

__END__
begin 1 at - line 4.
destroy at - line 3.

>
> If BEGIN and other named blocks are implemented as subroutines, with
sundry
> ramifications on @_ and other things (caller?), that is an implementation
> detail, or even an implementation wart. These warts (if so deemed) should
> definitely be made clear in the docs, or done away with if possible.
>
> FWIW, I have round tuits, maybe even enough to write docs for said wart,
> but not nearly enough to modify Perl's handling of these blocks.

I don’t consider them warts, but I wouldn’t mind better documentation,
including the fact that DESTROY and AUTOLOAD are also special, in that
‘sub’ can be omitted.

--

Father Chrysostomos


---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.