Skip Menu |

This queue is for tickets about the P CPAN distribution.

Report information
The Basics
Id: 89054
Status: resolved
Priority: 0/
Queue: P

People
Owner: Nobody in particular
Requestors: l.mai [...] web.de
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.0.20
Fixed in: (no value)



Subject: random 1; in the middle of the module
Line 181 of P.pm is: 1;} This '1;' does nothing and can be removed.
From: perl-diddler [...] tlinx.org
On Mon Sep 30 07:52:18 2013, l.mai@web.de wrote: Show quoted text
> Line 181 of P.pm is: > > 1;} > > This '1;' does nothing and can be removed.
---- This is the last line of "package P". package main continues after that. when one does a "use packagename", I was under the impression that, generally speaking, it needs to return a "true" value. Thus it has 1; as the last line of the package definition. I understand that with P included in a file with another package that the end value isn't used, however, I try to develop my packages to be ready for separation without requiring source changes. That was an issue on p5p some time back that I eventually solved with the "use mem" pragma that allows a module to be used directly from its "in-mem"[ory] version. With that in place, and the 1 at the end of the package, it should be fairly trivial to split a package to a separate file if desired -- thus I always try to put a 1; at the end of package definitions. Unless it is causing a problem, it isn't really random and does serve my purposes, so I'd rather not remove it needlessly. Is it causing some problem? Thanks!
Subject: Re: [rt.cpan.org #89054] random 1; in the middle of the module
Date: Tue, 01 Oct 2013 08:34:39 +0200
To: bug-P [...] rt.cpan.org
From: Lukas Mai <l.mai [...] web.de>
On 01.10.2013 08:10, perl-diddler@tlinx.org via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=89054 > > > On Mon Sep 30 07:52:18 2013, l.mai@web.de wrote:
>> Line 181 of P.pm is: >> >> 1;} >> >> This '1;' does nothing and can be removed.
> ---- > This is the last line of "package P". package main continues after that. when one does a "use packagename", I was under the impression that, generally speaking, it needs to return a "true" value. Thus it has 1; as the last line of the package definition. > > I understand that with P included in a file with another package that the end value isn't used, however, I try to develop my packages to be ready for separation without requiring source changes. That was an issue on p5p some time back that I eventually solved with the "use mem" pragma that allows a module to be used directly from its "in-mem"[ory] version. > > With that in place, and the 1 at the end of the package, it should be fairly trivial to split a package to a separate file if desired -- thus I always try to put a 1; at the end of package definitions. > > Unless it is causing a problem, it isn't really random and does serve my purposes, so I'd rather not remove it needlessly. > > Is it causing some problem?
It's not causing problems but to me it indicates the author doesn't really understand use/require. The "1;" doesn't end a *package*; it's the return value of the *file*. (For some reason it's customary to leave out 'return' in modules, though.) Example: ===Foo.pm==== { package Foo; ... } { package Bar; ... } return 1; __END__ This can be loaded with 'use Foo' because it's in the file Foo.pm and returns a true value. Note that file loading doesn't care about packages, only files. ===Foo2.pm==== { package Foo; ... } { package Bar; ... } 1; __END__ ^ Same thing, but this time we use an implicit return value (last expression evaluated in the file). Ultimately it's a style issue. Personally I prefer "1;" (or "'ok';") at the end of the file because in my mind it's part of the file loading system, not any package. If you disagree, feel free to close this bug. -- Lukas Mai <l.mai@web.de>
Comment added to 1st occurrence in code: 1;} #value 1 placed at as w/most of my end-of-packages (rt#89054)