File Coverage

blib/lib/Net/Stomp/MooseHelpers/Types.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Net::Stomp::MooseHelpers::Types;
2             $Net::Stomp::MooseHelpers::Types::VERSION = '3.0';
3             {
4             $Net::Stomp::MooseHelpers::Types::DIST = 'Net-Stomp-MooseHelpers';
5             }
6 4         36 use MooseX::Types -declare =>
7             [qw(
8             NetStompish
9             Hostname PortNumber
10             ServerConfig ServerConfigList
11             Headers
12             SubscriptionConfig SubscriptionConfigList
13             Destination
14             Permissions OctalPermissions
15 4     4   170649 )];
  4         525828  
16 4     4   33347 use MooseX::Types::Moose qw(Bool Str Value Int ArrayRef HashRef);
  4         43987  
  4         39  
17 4     4   22102 use MooseX::Types::Structured qw(Dict Optional Map);
  4         1453892  
  4         30  
18 4     4   1749 use namespace::autoclean;
  4         9  
  4         36  
19              
20             # ABSTRACT: type definitions for Net::Stomp::MooseHelpers
21              
22              
23             duck_type NetStompish, [qw(connect
24             subscribe unsubscribe
25             receive_frame ack
26             send send_frame current_host)];
27              
28              
29             subtype Hostname, as Str; # maybe too lax?
30              
31              
32             subtype PortNumber, as Int,
33             where { $_ > 0 and $_ < 65536 };
34              
35              
36             subtype ServerConfig, as Dict[
37             hostname => Hostname,
38             port => PortNumber,
39             ssl => Optional[Bool],
40             ssl_options => Optional[HashRef],
41             connect_headers => Optional[HashRef],
42             subscribe_headers => Optional[HashRef],
43             ];
44              
45              
46             subtype ServerConfigList, as ArrayRef[ServerConfig];
47             coerce ServerConfigList, from ServerConfig, via { [shift] };
48              
49              
50             subtype Headers, as Map[Str,Value];
51              
52              
53             subtype SubscriptionConfig, as Dict[
54             destination => Destination,
55             path_info => Optional[Str],
56             headers => Optional[Map[Str,Value]],
57             ];
58              
59              
60             subtype SubscriptionConfigList, as ArrayRef[SubscriptionConfig];
61             coerce SubscriptionConfigList, from SubscriptionConfig, via { [shift] };
62              
63              
64             subtype Destination, as Str,
65             where { m{^/(?:queue|topic)/} };
66              
67              
68             subtype Permissions, as Int,
69             where { $_ == 0 or not /^0/ };
70             subtype OctalPermissions, as Str,
71             where { /\A0[0-7]{3,4}\z/ };
72             coerce Permissions,
73             from OctalPermissions,
74             via { oct($_) };
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             Net::Stomp::MooseHelpers::Types - type definitions for Net::Stomp::MooseHelpers
85              
86             =head1 VERSION
87              
88             version 3.0
89              
90             =head1 TYPES
91              
92             =head2 C<NetStompish>
93              
94             Any object that can C<connect>, C<subscribe>, C<unsubscribe>,
95             C<receive_frame>, C<ack>, C<send>, C<send_frame>.
96              
97             =head2 C<Hostname>
98              
99             A string.
100              
101             =head2 C<PortNumber>
102              
103             An integer between 1 and 65535.
104              
105             =head2 C<ServerConfig>
106              
107             A hashref with these keys:
108              
109             =over 4
110              
111             =item C<hostname>
112              
113             with value matching L</Hostname>
114              
115             =item C<port>
116              
117             value matching L</PortNumber>
118              
119             =item C<connect_headers>
120              
121             optional, a hashref value (credentials go here, as C<login> / C<passcode>)
122              
123             =item C<subscribe_headers>
124              
125             optional, a hashref value
126              
127             =item C<ssl>
128              
129             optional boolean, defaults to false
130              
131             =item C<ssl_options>
132              
133             optional, a hashref value, passed to L<IO::Socket::SSL> from inside
134             L<Net::Stomp>
135              
136             =back
137              
138             See L<Net::Stomp::MooseHelpers::CanConnect/connect>.
139              
140             =head2 C<ServerConfigList>
141              
142             An arrayref of L</ServerConfig> values. Can be coerced from a single
143             L</ServerConfig>.
144              
145             =head2 C<Headers>
146              
147             A hashref.
148              
149             =head2 C<SubscriptionConfig>
150              
151             A hashref having a C<destination> key (with a value matching
152             L</Destination>), and optionally a C<path_info> key (with value
153             matching L</Path>) and a C<headers> key (with a hashref value). See
154             L<Net::Stomp::MooseHelpers::CanSubscribe/subscribe>.
155              
156             =head2 C<SubscriptionConfigList>
157              
158             An arrayref of L</SubscriptionConfig> values. Can be coerced from a
159             single L</SubscriptionConfig>.
160              
161             =head2 C<Destination>
162              
163             A string starting with C</queue/> or C</topic/>.
164              
165             =head2 C<Permissions>, C<OctalPermissions>
166              
167             UNIX-style file-system permissions. C<Permissions> is an integer type,
168             suitable to be passed to C<chmod>. C<OctalPermissions> is a string
169             type coercible to C<Permissions>, allowing you to specify permissions
170             in the usual C<"0644"> form.
171              
172             =head1 AUTHOR
173              
174             Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
175              
176             =head1 COPYRIGHT AND LICENSE
177              
178             This software is copyright (c) 2014 by Net-a-porter.com.
179              
180             This is free software; you can redistribute it and/or modify it under
181             the same terms as the Perl 5 programming language system itself.
182              
183             =cut