File: stringable.t

package info (click to toggle)
libmoosex-types-stringlike-perl 0.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 200; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use 5.006;
use strict;
use warnings;
use Test::More 0.96;

{
  package BlessedPath;
  use overload q{""} => sub { "${$_[0]}" };
  sub new { my ($class, $path) = @_; return bless \$path, $class; }
}

{
  package Foo;
  use Moose;
  use MooseX::Types::Stringlike qw/Stringable Stringlike/;
  
  has path => ( is => 'ro', isa => Stringlike, coerce => 1 );
  has path_obj => (is => 'ro', isa => Stringable );
}


my $obj = eval {
  Foo->new(
    path => BlessedPath->new("./t"),
    path_obj => BlessedPath->new("./lib"),
  )
};

is( $@, '', "object created without exception" );

is( ref($obj->path), '', "path attribute has been coerced to string" );
is( ref($obj->path_obj), 'BlessedPath', "path_obj is still an object" );

done_testing;
#
# This file is part of MooseX-Types-Stringlike
#
# This software is Copyright (c) 2012 by David Golden.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#