File Coverage

blib/lib/MooseFS.pm
Criterion Covered Total %
statement 15 36 41.6
branch 0 10 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 0 1 0.0
total 20 58 34.4


line stmt bran cond sub pod time code
1             package MooseFS;
2              
3 10     10   95714 use 5.006;
  10         271  
  10         415  
4 10     10   58 use strict;
  10         19  
  10         341  
5 10     10   50 use warnings FATAL => 'all';
  10         24  
  10         388  
6 10     10   1690 use Moo;
  10         38849  
  10         57  
7 10     10   8785 use IO::Socket::INET;
  10         92337  
  10         121  
8              
9             =head1 NAME
10              
11             MooseFS - The MooseFS Info API!
12              
13             =head1 VERSION
14              
15             Version 0.04
16              
17             =cut
18              
19             our $VERSION = '0.04';
20              
21              
22             =head1 SYNOPSIS
23              
24             The large portions of the code in my library have been taken directly from the Web UI that ships with MooseFS.
25              
26             Just use different objects to get different informations of the MooseFS cluster.
27              
28              
29             use MooseFS::Server;
30             my $mfs = MooseFS::Server->new(
31             masterhost => '127.0.0.1'
32             );
33             say Dumper $mfs->info;
34             say for $mfs->list;
35             say $mfs->masterversion;
36             ...
37              
38             =head1 LIMIT
39              
40             Don't support version below 1.6.13 by now.
41              
42             =cut
43              
44             has masterhost => (
45             is => 'ro',
46             default => sub { '127.0.0.1' }
47             );
48              
49             has masterport => (
50             is => 'ro',
51             default => sub { 9421 }
52             );
53              
54             has masterversion => (
55             is => 'ro',
56             lazy => 1,
57             builder => '_check_version',
58             );
59              
60             has sock => (
61             is => 'rw',
62             lazy => 1,
63             builder => '_create_sock',
64             );
65              
66             has info => (
67             is => 'rw',
68             );
69              
70             sub _create_sock {
71 0     0     my $self = shift;
72 0           IO::Socket::INET->new(
73             PeerAddr => $self->masterhost,
74             PeerPort => $self->masterport,
75             Proto => 'tcp',
76             );
77             };
78              
79             sub _check_version {
80 0     0     my $self = shift;
81 0           my $s = $self->sock;
82 0           print $s pack('(LL)>', 510, 0);
83 0           my $header = $self->myrecv($s, 8);
84 0           my ($cmd, $length) = unpack('(LL)>', $header);
85 0           my $data = $self->myrecv($s, $length);
86 0 0         if ( $cmd == 511 ) {
87 0 0 0       if ( $length == 52 ) {
    0          
    0          
88 0           return 1400;
89             } elsif ( $length == 60 ) {
90 0           return 1500;
91             } elsif ( $length == 68 or $length == 76) {
92 0           return sprintf "%d%d%02d", unpack("(SCC)>", substr($data, 0, 4));
93             };
94             };
95             };
96              
97             sub myrecv {
98 0     0 0   my ($self, $socket, $len) = @_;
99 0           my $msg = '';
100 0           while ( length($msg) < $len ) {
101 0           my $chunk;
102 0           sysread $socket, $chunk, $len-length($msg);
103 0 0         die "Socket Close." if $chunk eq '';
104 0           $msg .= $chunk;
105             }
106 0           return $msg;
107             };
108              
109             =head1 SEE ALSO
110              
111             =over 4
112            
113             =item L
114              
115             =item L
116              
117             =item L
118              
119             =back
120              
121             =head1 AUTHOR
122              
123             chenryn, C<< >>
124              
125             =head1 BUGS
126              
127             Please report any bugs or feature requests to C, or through
128             the web interface at L. I will be notified, and then you'll
129             automatically be notified of progress on your bug as I make changes.
130              
131              
132              
133              
134             =head1 SUPPORT
135              
136             You can find documentation for this module with the perldoc command.
137              
138             perldoc MooseFS
139              
140              
141             =head1 ACKNOWLEDGEMENTS
142              
143              
144             =head1 LICENSE AND COPYRIGHT
145              
146             Copyright 2013 chenryn.
147              
148             This program is free software; you can redistribute it and/or modify it
149             under the terms of the the Artistic License (2.0). You may obtain a
150             copy of the full license at:
151              
152             L
153              
154             Any use, modification, and distribution of the Standard or Modified
155             Versions is governed by this Artistic License. By using, modifying or
156             distributing the Package, you accept this license. Do not use, modify,
157             or distribute the Package, if you do not accept this license.
158              
159             If your Modified Version has been derived from a Modified Version made
160             by someone other than you, you are nevertheless required to ensure that
161             your Modified Version complies with the requirements of this license.
162              
163             This license does not grant you the right to use any trademark, service
164             mark, tradename, or logo of the Copyright Holder.
165              
166             This license includes the non-exclusive, worldwide, free-of-charge
167             patent license to make, have made, use, offer to sell, sell, import and
168             otherwise transfer the Package with respect to any patent claims
169             licensable by the Copyright Holder that are necessarily infringed by the
170             Package. If you institute patent litigation (including a cross-claim or
171             counterclaim) against any party alleging that the Package constitutes
172             direct or contributory patent infringement, then this Artistic License
173             to you shall terminate on the date that such litigation is filed.
174              
175             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
176             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
177             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
178             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
179             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
180             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
181             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
182             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
183              
184              
185             =cut
186              
187             1; # End of MooseFS