If you want to require "use MyCode::ProcessC" be added to the "data type" class, then that is just standard, run-of-the-mill Exporter.pm work with @EXPORT= qw( process_c ).
But it sounds like you want the "use MyCode::ProcessC" to be somewhere else. Since you are useing and not requireing, you could put the exporting code into MyCode::ProcessC::import (rather than a BEGIN block), which means that it would be called multiple times if you use MyCode::ProcessC multiple times. But that might be a good thing if you want to be "general purpose".
For example, you could require: use MyCode::ProcessC( "DataType::Class" ); in the main script and have MyCode/ProcessC.pm contain:
- tye (but my friends call me "Tye")package MyCode::ProcessC; use strict; sub import { if( 2 != @_ ) { require Carp; Carp::croak( 'Usage: use ',__PACKAGE__, '( "DataType::Class" )' ); } my( $self, $class )= @_; for my $meth ( qw( process_c ) ) { no strict 'refs'; *{$class."::".$meth}= \&$meth; } }
In reply to (tye)Re: Possible Stupid Perl Trick - Importing method into object class?
by tye
in thread Possible Stupid Perl Trick - Importing method into object class?
by Masem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |