Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Use method/function signatures with Perl

by Ovid (Cardinal)
on Dec 06, 2004 at 00:40 UTC ( #412554=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub name {
        my $self = shift;
        if (@_) {
    ...
        }
        return $self->{name};
    }
    
  2. or download this
    $person->name;         # get the name
    $person->name("Ovid"); # set the name
    
  3. or download this
    $person->name(qw/Publius Ovidius Naso/);
    # or
    $person->name([qw/Publius Ovidius Naso/]);
    # or
    my $name = Name->new("Publius Ovidius Naso");
    $person->name($name);
    
  4. or download this
    sub name {
        my $self = shift;
        if (1 == @_ && ! ref $_[0]) {
    ...
            croak "Unknown arguments to name()";
        }
    }
    
  5. or download this
    sub name($self) {
        return $self->{name};
    }
    ...
        $self->{name} = $name;
        return $self;
    }
    
  6. or download this
    use Sub::Signatures;
    
    sub foo($bar) {
    ...
    foo(1);     # prints 1
    foo(1,2);   # prints 1, 2
    foo(1,2,3); # fatal error
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://412554]
Approved by atcroft
Front-paged by astaines
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2015-07-03 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (49 votes), past polls