package Sam::Constants; use strict; use warnings; use constant { ABC_1 => 1, ABC_2 => 2, ABC_3 => 3, DEF_1 => 4, DEF_2 => 5, DEF_3 => 6, GHI_1 => 7, GHI_2 => 8, GHI_3 => 9, }; BEGIN { use Exporter 'import'; my @abc = qw{ABC_1 ABC_2 ABC_3}; my @def = qw{DEF_1 DEF_2 DEF_3}; my @ghi = qw{GHI_1 GHI_2 GHI_3}; my @abcdef = (@abc, @def); my @all = (@abc, @def, @ghi); our @EXPORT_OK = @all; our %EXPORT_TAGS = ( abc => [@abc], def => [@def], ghi => [@ghi], abcdef => [@abcdef], all => [@all], ); } 1; #### $ alias perl_sam_const alias perl_sam_const='perl -I/home/ken/tmp/pm_11139384/lib -Mstrict -Mwarnings -E' #### # import a single constant $ perl_sam_const 'use Sam::Constants qw{ABC_2}; say ABC_2' 2 # check that other ABC_* constants are not imported $ perl_sam_const 'use Sam::Constants qw{ABC_2}; say for ABC_1, ABC_2, ABC_3' Bareword "ABC_1" not allowed while "strict subs" in use at -e line 1. Bareword "ABC_3" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. # import all ABC_* constants $ perl_sam_const 'use Sam::Constants qw{:abc}; say for ABC_1, ABC_2, ABC_3' 1 2 3 # import all ABC_* and GHI_* constants (using two tags) $ perl_sam_const 'use Sam::Constants qw{:abc :ghi}; say for ABC_1, GHI_2' 1 8 # import all ABC_* and DEF_* constants (using just one tag) $ perl_sam_const 'use Sam::Constants qw{:abcdef}; say for DEF_3, ABC_3' 6 3 # import all constants $ perl_sam_const 'use Sam::Constants qw{:all}; say for ABC_1, DEF_2, GHI_3' 1 5 9