]> git.vpit.fr Git - perl/modules/Sub-Prototype-Util.git/blob - README
Importing Sub-Prototype-Util-0.05.tar.gz
[perl/modules/Sub-Prototype-Util.git] / README
1 NAME
2     Sub::Prototype::Util - Prototype-related utility routines.
3
4 VERSION
5     Version 0.05
6
7 SYNOPSIS
8         use Sub::Prototype::Util qw/flatten recall/;
9
10         my @a = qw/a b c/;
11         my @args = ( \@a, 1, { d => 2 }, undef, 3 );
12
13         my @flat = flatten '\@$;$', @args; # ('a', 'b', 'c', 1, { d => 2 })
14         recall 'CORE::push', @args; # @a contains 'a', 'b', 'c', 1, { d => 2 }, undef, 3
15
16 DESCRIPTION
17     Prototypes are evil, but sometimes you just have to bear with them,
18     especially when messing with core functions. This module provides
19     several utilities aimed at facilitating "overloading" of prototyped
20     functions.
21
22     They all handle 5.10's "_" prototype.
23
24 FUNCTIONS
25   "flatten $proto, @args"
26     Flattens the array @args according to the prototype $proto. When @args
27     is what @_ is after calling a subroutine with prototype $proto,
28     "flatten" returns the list of what @_ would have been if there were no
29     prototype.
30
31   "recall $name, @args"
32     Calls the function $name with the prototyped argument list @args. That
33     is, @args should be what @_ is when you define a subroutine with the
34     same prototype as $name. For example,
35
36         my $a = [ ];
37         recall 'CORE::push', $a, 1, 2, 3;
38
39     will call "push @$a, 1, 2, 3" and so fill the arrayref $a with "1, 2,
40     3". This is especially needed for core functions because you can't
41     "goto" into them.
42
43     You can also force the use of a specific prototype. In this case, $name
44     must be a hash reference that holds exactly one key/value pair, the key
45     being the function name and the value the prototpye that should be used
46     to call it.
47
48         recall { 'CORE::push' => '\@$' }, $a, 1, 2, 3; # will only push 1
49
50     This allows you to recall into "CORE::grep" and "CORE::map" by using the
51     "\&@" prototype :
52
53         sub mygrep (&@) { recall { 'CORE::grep' => '\&@' }, @_ } # the prototypes are intentionally different
54
55 EXPORT
56     The functions "flatten" and "recall" are only exported on request,
57     either by providing their name or by the ':funcs' and ':all' tags.
58
59 DEPENDENCIES
60     Carp, Exporter (core modules since perl 5), Scalar::Util (since 5.7.3).
61
62 AUTHOR
63     Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
64
65     You can contact me by mail or on #perl @ FreeNode (vincent or
66     Prof_Vince).
67
68 BUGS
69     Please report any bugs or feature requests to "bug-sub-prototype-util at
70     rt.cpan.org", or through the web interface at
71     <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sub-Prototype-Util>. I
72     will be notified, and then you'll automatically be notified of progress
73     on your bug as I make changes.
74
75 SUPPORT
76     You can find documentation for this module with the perldoc command.
77
78         perldoc Sub::Prototype::Util
79
80     Tests code coverage report is available at
81     <http://www.profvince.com/perl/cover/Sub-Prototype-Util>.
82
83 COPYRIGHT & LICENSE
84     Copyright 2008 Vincent Pit, all rights reserved.
85
86     This program is free software; you can redistribute it and/or modify it
87     under the same terms as Perl itself.
88