package Cswitch;
use strict;
use warnings;
use Devel::Declare;
sub import {
print "Import called with @_";
my $class = shift;
my $caller = caller;
Devel::Declare::setup_for(
$caller,
{
switch => { const => \&pSwitch },
case => { const => \&pcase },
}
);
no strict;
*{ $caller . '::switch' } = sub () { };
*{ $caller . '::case' } = sub () { };
}
sub pSwitch {
print "pSwitch: @_";
}
sub pCase {
print "pCase: @_";
}
1;
####
#! perl -slw
use strict;
use Cswitch;
switch 1, {
case 1, {
print 'Got 1';
};
case 2, {
print 'Got 2'
},
};
##
##
C:\test>t-DevDec.pl
Import called with Cswitch
Number found where operator expected at C:\test\t-DevDec.pl line 5, near "switch 1"
(Do you need to predeclare switch?)
Number found where operator expected at C:\test\t-DevDec.pl line 6, near "case 1"
(Do you need to predeclare case?)
Number found where operator expected at C:\test\t-DevDec.pl line 9, near "case 2"
(Do you need to predeclare case?)
syntax error at C:\test\t-DevDec.pl line 5, near "switch 1"
Execution of C:\test\t-DevDec.pl aborted due to compilation errors.