WantWant is a Perl module created to implement the `want' command. | |
Download |
Want Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Robin Houston
- Publisher web site:
- http://search.cpan.org/~robin/Want-0.17/Want.pm
Want Tags
Want Description
Want is a Perl module created to implement the `want' command. Want is a Perl module created to implement the `want' command.SYNOPSIS use Want; sub foo :lvalue { if (want(qw'LVALUE ASSIGN')) { print "We have been assigned ", want('ASSIGN'); lnoreturn; } elsif (want('LIST')) { rreturn (1, 2, 3); } elsif (want('BOOL')) { rreturn 0; } elsif (want(qw'SCALAR !REF')) { rreturn 23; } elsif (want('HASH')) { rreturn { foo => 17, bar => 23 }; } return }This module generalises the mechanism of the wantarray function, allowing a function to determine in some detail how its return value is going to be immediately used. ...EXAMPLES use Carp 'croak'; use Want 'howmany'; sub numbers { my $count = howmany(); croak("Can't make an infinite list") if !defined($count); return (1..$count); } my ($one, $two, $three) = numbers(); use Want 'want'; sub pi () { if (want('ARRAY')) { return ; } elsif (want('LIST')) { return (3, 1, 4, 1, 5, 9); } else { return 3; } } print pi->; # prints 4 print ((pi)); # prints 1 sub backstr :lvalue { if (want(qw'LVALUE ASSIGN')) { my ($a) = want('ASSIGN'); $_ = reverse $a; return undef; } elsif (want('RVALUE')) { my $t = scalar reverse $_; } else { carp("Not in ASSIGN context"); } return } print "foo -> ", backstr("foo"), "n"; # foo -> oof backstr(my $robin) = "nibor"; print "$robin is now $robinn"; # $robin is now robin Requirements: · Perl
Want Related Software