in reply to Re: Ideal way to pass a file to a module
in thread Ideal way to pass a file to a module
I agree, but I'd suggest a different interface: use separate functions for the different cases, and implement them in terms of one another. That allows users to import and call just those functions that they need.
sub add_cr_to_str { # ... implementation goes here } sub add_cr_to_str_ref { add_cr_to_str( ${$_[0]} ) } sub add_cr_to_fh { add_cr_to_str( do { local $/; <$_[0]> } ) } sub add_cr_to_fn { require FileHandle; add_cr_to_sh( FileHandle->new( @_ ) ) }
Most of those are just convenience functions, but if you later change your mind about which implementations are "primary", it's pretty easy to shuffle things around while maintaining the same interface.
sub add_cr_to_str { add_cr_to_str_ref( \($_[0]) ) } sub add_cr_to_str_ref { # ... implementation goes here }
|
|---|