Sawyer X > Data-Collector > Data::Collector::Info



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.15   Source  


Data::Collector::Info - A base class for information classes


version 0.15


    package Data::Collector::Info::Bamba;
    use Moose;
    extends 'Data::Collector::Info';

    sub info_keys { ['bamba'] }

    sub _build_raw_data {
        my $self   = shift;
        my $engine = $self->engine;

        return $engine->run(/usr/bin/bamba-counter);

    sub all {
        my $self = shift;
        return $self->raw_data;

This synopsis shows how to create your own piece of info (in this case it counts bambas (which is a peanut snack).


Since all info modules return values which are all gathered in a single hash, they might step on each other's toes. In order to avoid this, there is a registry that keeps all the keys from each info module. If you create an info module, you should register your keys in the registry. This is best done while subclassing the load method as shown in the synopsis.



This contains the data received from the engine. You should implement a builder for it under the name _build_raw_data.


This contains the object of the engine the info module would be using to fetch information. This is set by Data::Collector on initialize.



This method registers keys in the registry. You can provide as many as you want.

It should be called using the class, not any object, as such:


Now if anyone else will try to register another key (such as another bamba module), Data::Collector::Info will prevent it from happening.


This method can be used to remove keys from the registry. However, refrain from using this method in order to provide two collections. The reason is that there is still a boolean in Data::Collector that will stll prevent you from running another collection.


This method ostensibly clears all keys from the registry. In actuality, it simply replaces the existing registry with a new one.


This method will run before an information module is loaded. You should subclass this method to indicate what keys you're going to acquire.

Any type of data other than an arrayref will be ignored.

You must subclass this method or your code will die.


This method will run when an information module is loaded. You should subclass this method if you're writing an info module that requires some extra bells and whistles you could use this method.

However, you do not have to subclass it.


This method is run to get all the information attainable by the info module.

If you have several bits of information in your module, you can have methods for each, but they should all be attainable using the all method.

You must subclass this method or your code will die.


This is a Moose method which is done after module initialization. It's set to run the load method of the module. However, if you wish to do something else, you could subclass it.

Unless you're pulling off something especially fancy, subclass the load and use that instead - for the sake of clarity if not anything else.


Sawyer X <>


This software is copyright (c) 2012 by Sawyer X.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: