Vincent Pit > Sub-Nary-0.03 > Sub::Nary

Download:
Sub-Nary-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Stalled  1
View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Sub::Nary - Try to count how many elements a subroutine can return in list context.

VERSION ^

Version 0.03

SYNOPSIS ^

    use Sub::Nary;

    my $sn = Sub::Nary->new();
    my $r  = $sn->nary(\&hlagh);

DESCRIPTION ^

This module uses the B framework to walk into subroutines and try to guess how many scalars are likely to be returned in list context. It's not always possible to give a definitive answer to this question at compile time, so the results are given in terms of "probability of return" (to be understood in a sense described below).

METHODS ^

new

The usual constructor. Currently takes no argument.

nary $coderef

Takes a code reference to a named or anonymous subroutine, and returns a hash reference whose keys are the possible numbers of returning scalars, and the corresponding values the "probability" to get them. The special key 'list' is used to denote a possibly infinite number of returned arguments. The return value hence would look at

    { 1 => 0.2, 2 => 0.4, 4 => 0.3, list => 0.1 }

that is, we should get 1 scalar 1 time over 5 and so on. The sum of all values is 1. The returned result, and all the results obtained from intermediate subs, are cached into the object.

flush

Flushes the Sub::Nary object cache. Returns the object itself.

PROBABILITY OF RETURN ^

The probability is computed as such :

EXPORT ^

An object-oriented module shouldn't export any function, and so does this one.

CAVEATS ^

The algorithm may be pessimistic (things seen as list while they are of fixed length) but not optimistic (the opposite, duh).

wantarray isn't specialized when encountered in the optree.

DEPENDENCIES ^

perl 5.8.1.

Carp (standard since perl 5), B (since perl 5.005) and XSLoader (since perl 5.006).

AUTHOR ^

Vincent Pit, <perl at profvince.com>, http://www.profvince.com.

You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).

BUGS ^

Please report any bugs or feature requests to bug-b-nary at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sub-Nary. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Sub::Nary

Tests code coverage report is available at http://www.profvince.com/perl/cover/Sub-Nary.

ACKNOWLEDGEMENTS ^

Thanks to Sebastien Aperghis-Tramoni for helping to name this module.

COPYRIGHT & LICENSE ^

Copyright 2008 Vincent Pit, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: