croak conventions in methods?

J

John Bokma

I check # of parameters in methods using:

@_ == x or croak 'usage $bla->bla( ... )';

Is there a style guide for the ... part, ie,

VALUE
[ VALUE, ... ]
{ KEY => VALUE, ... }

How about optional things?
[ VALUE* ]
[ VALUE+ ]
[ VALUE{1,9} ]
VALUE?
{ KEY => VALUE {1,9} }

Anyone?
 
J

John Bokma

Tad said:
There is no Perl content in your question you know...

Have a coffee first next time :-D
Found this:

http://support.packeteer.com/documentation/packetguide/current/info /
cli-conventions.htm

on the 1st page of results from googling for "usage conventions".

If I grep on 'usage: in C:\Perl I get 169 occurences.

e.g
:
lib\Net\NNTP.pm(228): @_ == 1 or croak 'usage: $nntp->help()';
lib\Net\NNTP.pm(238): @_ >= 2 or croak 'usage: $nntp->ihave( MESSAGE-ID
[, MESSAGE ])';
:

Does it now ring a bell or two?

I clearly stated in the subject: *croak* in *METHODS*
Where on Earth did you get that CLI idea from?

I mean, the part in the croak (the code I gave) was also a giveaway, or
did you think $bla-> is my CLI prompt?

Reread before you post.

Back to my original question, is there a convention of specifying
parameters, especial optional parameters in a croak 'usage: ' in a
method.

In for example:

sub send {
@_ >= 2 && @_ <= 4
or croak 'usage: $sock->send(BUF, [FLAGS, [TO]])';
my $sock = $_[0];
my $flags = $_[2] || 0;
my $peer = $_[3] || $sock->peername;
:

sub recv {
@_ == 3 || @_ == 4
or croak 'usage: $sock->recv(BUF, LEN [, FLAGS])';
my $sock = $_[0];
my $len = $_[2];
my $flags = $_[3] || 0;


(from IO::Socket)

the notation is inconsistent and confusing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top