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

Path::Tiny object is not coerced/stringified #68

Closed
oalders opened this issue Feb 14, 2024 · 4 comments
Closed

Path::Tiny object is not coerced/stringified #68

oalders opened this issue Feb 14, 2024 · 4 comments

Comments

@oalders
Copy link
Collaborator

oalders commented Feb 14, 2024

See metacpan/metacpan-api#1161 (comment) This could use a regression test.

@oalders
Copy link
Collaborator Author

oalders commented Feb 14, 2024

@XSven ^^

@XSven
Copy link
Contributor

XSven commented Feb 14, 2024

Ok I have compared the current master with the commit 1cc2320 (0.49 tag)

git diff 1cc2320 lib/OrePAN2/Injector.pm
diff --git a/lib/OrePAN2/Injector.pm b/lib/OrePAN2/Injector.pm
index 195b50b..aecf2fa 100644
--- a/lib/OrePAN2/Injector.pm
+++ b/lib/OrePAN2/Injector.pm
@@ -1,9 +1,9 @@
 package OrePAN2::Injector;

-use strict;
-use warnings;
 use utf8;

+use Moo;
+
 use Archive::Extract ();
 use Archive::Tar     qw( COMPRESS_GZIP );
 use CPAN::Meta       ();
@@ -16,20 +16,12 @@ use File::Temp       qw( tempdir );
 use File::pushd      qw( pushd );
 use HTTP::Tiny       ();
 use MetaCPAN::Client ();
+use Types::Standard  qw( CodeRef Str );

-sub new {
-    my $class = shift;
-    my %args  = @_ == 1 ? %{ $_[0] } : @_;
-    unless ( exists $args{directory} ) {
-        Carp::croak("Missing directory");
-    }
-    bless {
-        author => 'DUMMY',
-        %args
-    }, $class;
-}
+use namespace::clean;

-sub directory { shift->{directory} }
+has author => ( is => 'ro', isa => CodeRef | Str, default => 'DUMMY' );
+has directory => ( is => 'ro', isa => Str, required => 1 );

 sub inject {
     my ( $self, $source, $opts ) = @_;

I guess my Perl knowledge is not sufficient here, but where in the former (highlighted in red) implementation is the Path::Tiny to String conversion (stringification) happening?
My second question is should we really convert a Path::Tiny object back to a String (stringification) or should we work consistently with Path::Tiny objects as directory values and if necessary do a Str to Path::Tiny coercion.

@oalders
Copy link
Collaborator Author

oalders commented Feb 14, 2024

I don't think the stringification happens in this (red) diff. It would happen when directory gets concatenated with something else.

We could just use https://metacpan.org/pod/Types::Path::Tiny and coerce everything we get into a Path::Tiny object if there's some value in that. Otherwise coerce whatever we get into a string. Probably the former would be a good idea.

@oalders
Copy link
Collaborator Author

oalders commented Feb 20, 2024

Closed via #69

@oalders oalders closed this as completed Feb 20, 2024
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

No branches or pull requests

2 participants