use strict; use warnings; use Barcode::DataMatrix; use Data::Dumper; use Safe; sub DataMatrix2d{ my( $value ) = @_; my $mat = Barcode::DataMatrix->new()->barcode( $value ); return $mat; } my @safeops = ( qw( null stub scalar const padany lineseq leaveeval rv2gv ), # Basic variable IO and traversal qw( lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp slt sgt sle sge seq sne scmp ), # Comparators qw( preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec int hex oct abs pow multiply i_multiply divide i_divide modulo i_modulo add i_add subtract i_subtract ), # Base math qw( left_shift right_shift bit_and bit_xor bit_or negate i_negate not complement ), # Binary math qw( match split qr ), # Regex qw( cond_expr flip flop andassign orassign and or xor ), # Conditionals qw( atan2 sin cos exp log sqrt rand srand ), # Advanced math qw( rv2cv entersub leavesub pushmark list rv2sv anoncode refgen rv2av aassign rv2hv helem sassign exists concat subst length return enter leave ) # XXX ); my($safefuncs) = new Safe; $safefuncs->permit_only( @safeops ); $safefuncs->share( 'Barcode::DataMatrix' ); $safefuncs->share_from('main', [ 'DataMatrix2d' ]); my $functiontext = 'sub{my($R)=@_;$R->{AA}=DataMatrix2d("001")}'; my $func = $safefuncs->reval( $functiontext ); if( ref( $func ) ne 'CODE' ){ print "Not a code ref"; exit; } my $data = {}; my $ret = $func->( $data ); if( ref( $ret ) ne 'ARRAY' ){ print "Failed"; exit; } printf( "%s\n", Dumper( $ret ) );