Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OO interface #41

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add OO interface #41

wants to merge 5 commits into from

Conversation

zmughal
Copy link

@zmughal zmughal commented Oct 14, 2022

DRAFT: Start of OO interface.

This PR is just a placeholder. It still needs improvements to the tests, adding
the os_shell option (tentative name), documentation, and setting the
PATH/PATHEXT as options.

Connects to #40.

lib/File/Which.pm Outdated Show resolved Hide resolved
@zmughal zmughal force-pushed the oo-interface branch 3 times, most recently from e82deae to 77aa627 Compare October 15, 2022 02:48
@zmughal zmughal force-pushed the oo-interface branch 2 times, most recently from a9b7707 to f534a13 Compare October 15, 2022 03:30
sub new {
my ($class, %opts) = @_;

my $osname = exists $opts{os} ? $opts{os} : $^O;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure $^O is quite right for this, it has a lot of detail for unix like operating systems and not enough for windows. I think we want to know if it is unix, or win/vms/cyg/os9, and then we want something like win+powershell win+bash.

Copy link
Member

@plicease plicease Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have opts for os and shell. I still don't think $^O is right for os as Windows9x and WindowsNT are both MSWin32 unfortunately. I'm not too enthused about inventing our own categories for os, but we may have to. Note #41 (review) and #42

$self->{PATHEXT} = $self->_default_pathext;

if( exists $opts{fixed_paths} ) {
$self->{fixed_paths} = $opts{fixed_paths};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to delete from %opts and error if there is anything left over, that way we can add new options in the future, and if someone is trying to use those options on an older File::Which they will get an error.

if ( $self->_is_win ) {
# WinNT. PATHEXT might be set on Cygwin, but not used.
if ( $ENV{PATHEXT} ) {
push @PATHEXT, split /;/, $ENV{PATHEXT};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a Windows environment variable, but I think we should use Env qw( @PATHEXT ) for this and other list type environment variables. This will make it easier to test windows behavior on non-windows OS. Any tests that test default behavior can also use Env.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env is core as of Perl 5, so introducing it as a prereq shouldn't be a problem.

if ( $ENV{PATHEXT} ) {
push @PATHEXT, split /;/, $ENV{PATHEXT};
} else {
# Win9X or other: doesn't have PATHEXT, so needs hardcoded.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this isn't related to this PR, but if PATHEXT isn't supported on Windows 9x or DOS, then we shouldn't use it on those platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42

but we should at least consider that we may need to treat DOS/Windows9x as a different OS than WindowsNT.

$self->_is_win || $self->_is_vms || $self->_is_mac;
}
our $IMPLICIT_CURRENT_DIR = do {
File::Which->new->_default_implicit_current_dir;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for introducing this interface now. But we have to support it :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment (you are already doing that).

@plicease
Copy link
Member

I think this is the right approach.

  • need to decide on interface for specifying os/shell (I think shell is mostly only relevant on windows)
  • needs tests for major os/shell
  • documentation updates
  • document environment variables that we use

@plicease
Copy link
Member

plicease commented Oct 16, 2022

When you are writing the documentation, you can assume that we will bump the version to 2.00 when we add the OO interface. OO examples should look like this:

use File::Which 2.00;
my $which = File::Which->new;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants