documentation and attribution fixes
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Puppet.pm
1 package System::Introspector::Probe::Puppet;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     output_from_file
6     transform_exceptions
7 );
8
9 has classes_file => (
10     is      => 'ro',
11     default => sub { '/var/lib/puppet/state/classes.txt' },
12 );
13
14 has resources_file => (
15     is      => 'ro',
16     default => sub { '/var/lib/puppet/state/resources.txt' },
17 );
18
19 sub gather {
20     my ($self) = @_;
21     return {
22         classes     => $self->_gather_classes,
23         resources   => $self->_gather_resources,
24     };
25 }
26
27 sub _gather_resources {
28     my ($self) = @_;
29     return transform_exceptions {
30         my @lines = output_from_file $self->resources_file;
31         chomp @lines;
32         return [ map {
33             m{^(\w+)\[(.*)\]$}
34                 ? [$1, $2]
35                 : [__error__ => $_];
36         } @lines ];
37     };
38 }
39
40 sub _gather_classes {
41     my ($self) = @_;
42     return transform_exceptions {
43         my @lines = output_from_file $self->classes_file;
44         chomp @lines;
45         return \@lines;
46     };
47 }
48
49 1;
50
51 __END__
52
53 =head1 NAME
54
55 System::Introspector::Probe::Puppet - Gather puppet agent information
56
57 =head1 DESCRIPTION
58
59 Reads the C<classes.txt> and C<resources.txt> provided by puppet.
60
61 =head1 ATTRIBUTES
62
63 =head2 classes_file
64
65 The path to the C<classes.txt> puppet file.
66 Defaults to C</var/lib/puppet/state/classes.txt>.
67
68 =head2 resources_file
69
70 The path to the C<resources.txt> puppet file.
71 Defaults to C</var/lib/puppet/state/resources.txt>.
72
73 =head1 SEE ALSO
74
75 =over
76
77 =item L<System::Introspector>
78
79 =back
80
81 =head1 COPYRIGHT
82
83 Copyright (c) 2012 the L<System::Introspector>
84 L<AUTHOR|System::Introspector/AUTHOR>,
85 L<CONTRIBUTORS|System::Introspector/CONTRIBUTORS> and
86 L<SPONSORS|System::Introspector/SPONSORS>.
87
88 =head1 LICENSE
89
90 This library is free software and may be distributed under the same terms
91 as perl itself.
92
93 =cut