line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Resolver::CustomConverter 3.100455; |
2
|
|
|
|
|
|
|
# ABSTRACT: a one-off converter between any two types using a coderef |
3
|
1
|
|
|
1
|
|
7
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
4
|
1
|
|
|
1
|
|
5596
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
60
|
use MooseX::Types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
3488
|
use MooseX::Types::Moose qw(CodeRef); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
10
|
|
|
|
|
|
|
#pod |
11
|
|
|
|
|
|
|
#pod my $converter = Path::Resolver::CustomConverter->new({ |
12
|
|
|
|
|
|
|
#pod input_type => SomeType, |
13
|
|
|
|
|
|
|
#pod output_type => AnotherType, |
14
|
|
|
|
|
|
|
#pod converter => sub { ...return an AnotherType value... }, |
15
|
|
|
|
|
|
|
#pod }); |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod my $resolver = Path::Resolver::Resolver::Whatever->new({ |
18
|
|
|
|
|
|
|
#pod converter => $converter, |
19
|
|
|
|
|
|
|
#pod ... |
20
|
|
|
|
|
|
|
#pod }); |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod my $another = $resolver->entity_at('/foo/bar/baz.txt'); |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod This class lets you produce one-off converters between any two types using an |
25
|
|
|
|
|
|
|
#pod arbitrary hunk of code. |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod =attr input_type |
28
|
|
|
|
|
|
|
#pod |
29
|
|
|
|
|
|
|
#pod This is the L<Moose::Meta::TypeConstraint> for objects that the converter |
30
|
|
|
|
|
|
|
#pod expects to be handed as input. |
31
|
|
|
|
|
|
|
#pod |
32
|
|
|
|
|
|
|
#pod =attr output_type |
33
|
|
|
|
|
|
|
#pod |
34
|
|
|
|
|
|
|
#pod This is the L<Moose::Meta::TypeConstraint> for objects that the converter |
35
|
|
|
|
|
|
|
#pod promises to return as output. |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod =cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has [ qw(input_type output_type) ] => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => class_type('Moose::Meta::TypeConstraint'), |
42
|
|
|
|
|
|
|
required => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#pod =attr converter |
46
|
|
|
|
|
|
|
#pod |
47
|
|
|
|
|
|
|
#pod This is the coderef that will perform the conversion. It will be called like a |
48
|
|
|
|
|
|
|
#pod method: the first argument will be the converter object, followed by the value |
49
|
|
|
|
|
|
|
#pod to convert. |
50
|
|
|
|
|
|
|
#pod |
51
|
|
|
|
|
|
|
#pod =cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has converter => ( |
54
|
|
|
|
|
|
|
is => 'ro', |
55
|
|
|
|
|
|
|
isa => CodeRef, |
56
|
|
|
|
|
|
|
required => 1, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#pod =method convert |
60
|
|
|
|
|
|
|
#pod |
61
|
|
|
|
|
|
|
#pod This method accepts an input value, passes it to the converter coderef, and |
62
|
|
|
|
|
|
|
#pod returns the result. |
63
|
|
|
|
|
|
|
#pod |
64
|
|
|
|
|
|
|
#pod =cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub convert { |
67
|
9
|
|
|
9
|
1
|
230
|
$_[0]->converter->(@_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
with 'Path::Resolver::Role::Converter'; |
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=pod |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding UTF-8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Path::Resolver::CustomConverter - a one-off converter between any two types using a coderef |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 VERSION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
version 3.100455 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SYNOPSIS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $converter = Path::Resolver::CustomConverter->new({ |
90
|
|
|
|
|
|
|
input_type => SomeType, |
91
|
|
|
|
|
|
|
output_type => AnotherType, |
92
|
|
|
|
|
|
|
converter => sub { ...return an AnotherType value... }, |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $resolver = Path::Resolver::Resolver::Whatever->new({ |
96
|
|
|
|
|
|
|
converter => $converter, |
97
|
|
|
|
|
|
|
... |
98
|
|
|
|
|
|
|
}); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $another = $resolver->entity_at('/foo/bar/baz.txt'); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This class lets you produce one-off converters between any two types using an |
103
|
|
|
|
|
|
|
arbitrary hunk of code. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 PERL VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This library should run on perls released even a long time ago. It should work |
108
|
|
|
|
|
|
|
on any version of perl released in the last five years. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Although it may work on older versions of perl, no guarantee is made that the |
111
|
|
|
|
|
|
|
minimum required version will not be increased. The version may be increased |
112
|
|
|
|
|
|
|
for any reason, and there is no promise that patches will be accepted to lower |
113
|
|
|
|
|
|
|
the minimum required perl. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 input_type |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This is the L<Moose::Meta::TypeConstraint> for objects that the converter |
120
|
|
|
|
|
|
|
expects to be handed as input. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 output_type |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is the L<Moose::Meta::TypeConstraint> for objects that the converter |
125
|
|
|
|
|
|
|
promises to return as output. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 converter |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This is the coderef that will perform the conversion. It will be called like a |
130
|
|
|
|
|
|
|
method: the first argument will be the converter object, followed by the value |
131
|
|
|
|
|
|
|
to convert. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 convert |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This method accepts an input value, passes it to the converter coderef, and |
138
|
|
|
|
|
|
|
returns the result. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Ricardo Signes <cpan@semiotic.systems> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This software is copyright (c) 2022 by Ricardo Signes. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
149
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |