Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

new package syntax, where do I return true?

1 view
Skip to first unread message

Caleb Cushing

unread,
Jul 2, 2011, 12:00:06 AM7/2/11
to perl-docu...@perl.org
Having a little debate over this on a Perl::Critic ticket. I'm not
sure anyone is sure and the docs don't say.

https://rt.cpan.org/Ticket/Display.html?id=69234


is it package foo { ... 1; } or package foo { ... }; 1; ? or what?
and is it possible this could get clarified in the next edition of the
docs?
--
Caleb Cushing

http://xenoterracide.com

Chas. Owens

unread,
Jul 2, 2011, 8:53:39 AM7/2/11
to Caleb Cushing, perl-docu...@perl.org

My take on this is that

package Foo {
}

is the same thing as

{
package Foo;
}

Therefore, if your style allowed

{
package Foo;
1;
}

then it should allow

package Foo {
1;
}

However, I think you can make a good argument for not allowing that.
A module is not a package. The fact that it is customary for modules
to consist of one package sometimes confuses this, but there is no
requirement that a module include a package at all. From that basis,
I would argue that

package Foo {
}

1;

is more correct.

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Chas. Owens

unread,
Jul 2, 2011, 9:06:29 AM7/2/11
to Caleb Cushing, perl-docu...@perl.org
On Sat, Jul 2, 2011 at 08:53, Chas. Owens <chas....@gmail.com> wrote:
> On Sat, Jul 2, 2011 at 00:00, Caleb Cushing <xenote...@gmail.com> wrote:
>> Having a little debate over this on a Perl::Critic ticket. I'm not
>> sure anyone is sure and the docs don't say.
>>
>> https://rt.cpan.org/Ticket/Display.html?id=69234
snip

I have just reread perlmod and perlmodlib. It looks like they both
need a decent amount of work to bring them in line with the new
package syntax. For instance,

Give the module a version/issue/release number.

To be fully compatible with the Exporter and MakeMaker modules
you should store your module’s version number in a non‐my
package variable called $VERSION. This should be a floating
point number with at least two digits after the decimal (i.e.,
hundredths, e.g, "$VERSION = "0.01""). Don’t use a "1.3.2"
style version. See Exporter for details.

Should probably be changed to refer to the second package argument
with a caveat about possibly needing $VERSION to satisfy old static
analysis code.

brian d foy

unread,
Jul 2, 2011, 10:56:21 AM7/2/11
to perl-docu...@perl.org, Caleb Cushing
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <BANLkTikBYCOVX60JyEJNh27ETNYODUXT=w...@mail.gmail.com>, Caleb
Cushing <xenote...@gmail.com> wrote:

> Having a little debate over this on a Perl::Critic ticket. I'm not
> sure anyone is sure and the docs don't say.
>
> https://rt.cpan.org/Ticket/Display.html?id=69234
>
>
> is it package foo { ... 1; } or package foo { ... }; 1; ? or what?
> and is it possible this could get clarified in the next edition of the
> docs?

You don't need to return true from a package. You need to return true
from a use-d or require-d file so that the last statement in the file
returns true and perl knows it successfully loaded the file. It's
nothing to do with packages. You still need that true value even if you
have no packages declared in that file.

Caleb Cushing

unread,
Jul 2, 2011, 12:17:25 PM7/2/11
to Flavio Poletti, perl-docu...@perl.org
On Sat, Jul 2, 2011 at 1:13 AM, Flavio Poletti <fla...@polettix.it> wrote:
> i.e. it advices you to return a true value from the *file*, not from the
> package. This seems to be confirmed by require's documentation:
>
>                The file must return true as the last statement to indicate
>                successful execution of any initialization code, so it's
>                customary to end such a file with "1;" unless you're sure
> it'll
>                return true otherwise.  But it's better just to put the "1;",
>                in case you add more statements.
>
> Again, we're talking about the file, not any package inside.
>
> At this point, we could argue that putting the "1;" inside the block makes
> the whole code return a true value... but considering that the "1;" is
> file-related and that it seems difficult to handle properly in Perl::Critic,
> is this worth a crusade?

probably not, but I thought that this was the package that needed to
be returned true from and not the file. Now I understand. Thanks.

0 new messages