| 1 | #!/usr/bin/perl -c | ||
| 2 | |||
| 3 | package MooseX::Types::PerlIOLayerStr; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | MooseX::Types::PerlIOLayerStr - Type for PerlIO layer string | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | package My::Class; | ||
| 12 | use Moose; | ||
| 13 | use MooseX::Types::PerlIOLayerStr; | ||
| 14 | has file => ( isa => 'Str' ); | ||
| 15 | has layer => ( isa => 'PerlIOLayerStr' ); | ||
| 16 | |||
| 17 | package main; | ||
| 18 | my $fin = My::Class->new( file => 'Changelog', layer => ':utf8' ); | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | This module provides Moose type which represents PerlIO layer string. | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | |||
| 27 | use strict; | ||
| 28 | use warnings; | ||
| 29 | |||
| 30 | our $VERSION = '0.1004'; | ||
| 31 | |||
| 32 | use Moose::Util::TypeConstraints; | ||
| 33 | |||
| 34 | |||
| 35 | subtype PerlIOLayerStr => ( | ||
| 36 | as 'Str', | ||
| 37 | where { /^:/ }, | ||
| 38 | optimize_as { | ||
| 39 | defined $_[0] && !ref($_[0]) | ||
| 40 | && $_[0] =~ /^:/ | ||
| 41 | }, | ||
| 42 | ); | ||
| 43 | |||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | |||
| 48 | __END__ |