File Coverage

blib/lib/Struct/Path/PerlStyle/Functions.pm
Criterion Covered Total %
statement 23 23 100.0
branch 8 8 100.0
condition 4 6 66.6
subroutine 6 6 100.0
pod 1 1 100.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             package Struct::Path::PerlStyle::Functions;
2              
3 8     8   182 use 5.006;
  8         37  
4 8     8   55 use strict;
  8         23  
  8         213  
5 8     8   46 use warnings FATAL => 'all';
  8         19  
  8         364  
6 8     8   52 use parent 'Exporter';
  8         31  
  8         75  
7              
8 8     8   662 use Scalar::Util qw(looks_like_number);
  8         30  
  8         1930  
9              
10             our @EXPORT_OK = qw(
11             BACK
12             back
13             );
14              
15             # INPORTANT: upper case should be used for function names to avoid clashes
16             # with existing perl functions and operators.
17              
18             =head1 NAME
19              
20             Struct::Path::PerlStyle::Functions - Collection handy functions for
21             L hooks.
22              
23             =cut
24              
25             =head1 EXPORT
26              
27             Nothing is exported by default.
28              
29             =head1 Functions
30              
31             =head2 BACK, back
32              
33             Step back count times
34              
35             BACK(3); # go back 3 steps
36              
37             C returned when requested amount is greater than current step.
38             Lower-case 'back' is just an alias to 'BACK' for backward compatibility;
39             deprecated and will be removed in the future.
40              
41             =cut
42              
43             sub BACK {
44 6 100   6 1 2205 my $steps = defined $_[0] ? $_[0] : 1;
45              
46 6 100 66     41 return undef unless (looks_like_number $steps and int($steps) == $steps);
47 5 100       16 return 1 if ($steps == 0);
48 4 100 66     11 return undef if ($steps < 0 or $steps > @{$_{path}});
  4         18  
49              
50 3         6 splice @{$_{path}}, -$steps;
  3         10  
51 3         7 splice @{$_{refs}}, -$steps;
  3         18  
52             }
53              
54             *back = \&BACK; # for backward compatibility, deprecated
55              
56             =head1 AUTHOR
57              
58             Michael Samoglyadov, C<< >>
59              
60             =head1 BUGS
61              
62             Please report any bugs or feature requests to
63             C, or through the web interface at
64             L. I
65             will be notified, and then you'll automatically be notified of progress on
66             your bug as I make changes.
67              
68             =head1 SUPPORT
69              
70             You can find documentation for this module with the perldoc command.
71              
72             perldoc Struct::Path::PerlStyle::Functions
73              
74             You can also look for information at:
75              
76             =over 4
77              
78             =item * RT: CPAN's request tracker (report bugs here)
79              
80             L
81              
82             =item * AnnoCPAN: Annotated CPAN documentation
83              
84             L
85              
86             =item * CPAN Ratings
87              
88             L
89              
90             =item * Search CPAN
91              
92             L
93              
94             =back
95              
96             =head1 SEE ALSO
97              
98             L, L, L, L
99              
100             =head1 LICENSE AND COPYRIGHT
101              
102             Copyright 2018-2019 Michael Samoglyadov.
103              
104             This program is free software; you can redistribute it and/or modify it
105             under the terms of either: the GNU General Public License as published
106             by the Free Software Foundation; or the Artistic License.
107              
108             See L for more information.
109              
110             =cut
111              
112             1; # End of Struct::Path::PerlStyle::Functions