Skip Menu |

This queue is for tickets about the MooseX-Types-Path-Class CPAN distribution.

Report information
The Basics
Id: 70350
Status: resolved
Priority: 0/
Queue: MooseX-Types-Path-Class

People
Owner: Nobody in particular
Requestors: dagolden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.05
Fixed in: (no value)



Subject: Please coerce objects by stringifying
Please add a coercion for objects that stringifies them.
On Thu Aug 18 16:40:24 2011, DAGOLDEN wrote: Show quoted text
> Please add a coercion for objects that stringifies them
For any object (other than Path::Class::File/Dir), please stringify them during coercion. E.g. "$arg". This allows any file-like object that stringifies into a path to be used seamlessly. Consider a File::Temp object used to initialize an attribute of type Dir. A File::Temp object stringifies into a path, but can't be coerced into a Path::Class::Dir type because it's an object not a path: C.f. attached demo script and module Attribute (dir) does not pass the type constraint because: Validation failed for 'MooseX::Types::Path::Class::Dir' with value File::Temp=GLOB(0xbc1f68) at reader RT70350::dir (defined at RT70350.pm line 10) line 18 RT70350::dir('RT70350=HASH(0xba2f98)') called at rt70350.pl line 8
Subject: RT70350.pm
#!/usr/bin/env perl package RT70350; use strict; use warnings; use Moose 2; use MooseX::Types::Path::Class qw/Dir/; use namespace::autoclean; use File::Temp; has dir => ( is => 'ro', isa => Dir, coerce => 1, lazy_build => 1, ); sub _build_dir { my ($self) = @_; my $temp = File::Temp->new; return $temp; # "$temp" works } __PACKAGE__->meta->make_immutable; 1;
Subject: rt70350.pl
#!/usr/bin/env perl use v5.10; use strict; use warnings; use RT70350; my $obj = RT70350->new; say $obj->dir;
MooseX::Types::Stringlike and MooseX::Types::Path::Class::MoreCoercions were released to cpan. I've added a pointer to ::MoreCoercions in the pod (in git only so far).