| 1 | package FindApp::Utils::Syntax; | ||
| 2 | |||
| 3 | use v5.10; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use Sub::Name qw(subname); | ||
| 8 | |||
| 9 | use FindApp::Utils::Assert qw(:all); | ||
| 10 | use FindApp::Utils::Foreign qw(reftype); | ||
| 11 | |||
| 12 | ################################################################# | ||
| 13 | |||
| 14 | sub case ( & ) ; | ||
| 15 | sub case_fallthrough ( & ) ; | ||
| 16 | sub function ( $$ ) ; | ||
| 17 | |||
| 18 | ################################################################# | ||
| 19 | |||
| 20 | use Exporter qw(import); | ||
| 21 | our $VERSION = v1.0; | ||
| 22 | our @EXPORT_OK = qw( | ||
| 23 | case | ||
| 24 | case_fallthrough | ||
| 25 | function | ||
| 26 | ); | ||
| 27 | our %EXPORT_TAGS = ( | ||
| 28 | all => \@EXPORT_OK, | ||
| 29 | ); | ||
| 30 | |||
| 31 | ################################################################# | ||
| 32 | |||
| 33 | sub function($$) { | ||
| 34 | my($name, $code) = @_; | ||
| 35 | good_args(@_ == 2); | ||
| 36 | reftype($code) eq "CODE" || panic "wrong code type $code"; | ||
| 37 | |||
| 38 | for ($name) { | ||
| 39 | /^\w+(::\w+)*$/ || panic "bad function name $name"; | ||
| 40 | s/^/caller() . "::"/e | ||
| 41 | unless /::/; | ||
| 42 | } | ||
| 43 | |||
| 44 | ##print "$name\n"; | ||
| 45 | |||
| 46 | no strict "refs"; | ||
| 47 | no warnings "redefine"; | ||
| 48 | |||
| 49 | subname( $name => $code); | ||
| 50 | *$name = $code; | ||
| 51 | return \&$name; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub case(&) { | ||
| 55 | &case_fallthrough; | ||
| 56 | no warnings "exiting"; | ||
| 57 | next SWITCH; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub case_fallthrough(&) { | ||
| 61 | my($case) = @_; | ||
| 62 | &$case; | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; | ||
| 66 | |||
| 67 | =encoding utf8 | ||
| 68 | |||
| 69 | =head1 NAME | ||
| 70 | |||
| 71 | FindApp::Utils::Syntax - FIXME | ||
| 72 | |||
| 73 | =head1 SYNOPSIS | ||
| 74 | |||
| 75 | use FindApp::Utils::Syntax; | ||
| 76 | |||
| 77 | =head1 DESCRIPTION | ||
| 78 | |||
| 79 | =head2 Public Methods | ||
| 80 | |||
| 81 | =over | ||
| 82 | |||
| 83 | =item FIXME | ||
| 84 | |||
| 85 | =back | ||
| 86 | |||
| 87 | =head2 Exports | ||
| 88 | |||
| 89 | =over | ||
| 90 | |||
| 91 | =item case | ||
| 92 | |||
| 93 | =item case_fallthrough | ||
| 94 | |||
| 95 | =item function | ||
| 96 | |||
| 97 | =item FIXME | ||
| 98 | |||
| 99 | =back | ||
| 100 | |||
| 101 | =head1 EXAMPLES | ||
| 102 | |||
| 103 | =head1 ENVIRONMENT | ||
| 104 | |||
| 105 | =head1 SEE ALSO | ||
| 106 | |||
| 107 | =over | ||
| 108 | |||
| 109 | =item L<FindApp> | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =head1 CAVEATS AND PROVISOS | ||
| 114 | |||
| 115 | =head1 BUGS AND LIMITATIONS | ||
| 116 | |||
| 117 | =head1 HISTORY | ||
| 118 | |||
| 119 | =head1 AUTHOR | ||
| 120 | |||
| 121 | Tom Christiansen << <tchrist@perl.com> >> | ||
| 122 | |||
| 123 | =head1 LICENCE AND COPYRIGHT | ||
| 124 | |||
| 125 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||
| 126 | All Rights Reserved. | ||
| 127 | |||
| 128 | This module is free software; you can redistribute it and/or | ||
| 129 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||
| 130 | |||
| 131 | =cut | ||
| 132 |