Data::Type::Query - introspection of Data::Type library via DBI
use Data::Type qw(:all); use Data::Type::Query; my $dtq = Data::Type::Query->new(); foreach my $what ( $dtq->tables ) { my $sth = $dtq->dbh->do( "SELECT * FROM $what" ) || Carp::croak "$DBI::err"; while( my $href = $sth->fetchrow_hashref ) { print join ', ', $href; } } $dtq->depends(); print $dtq->toc(); my $href = $dtq->catalog(); print $href->{$_} for qw(types facets filters regexps);
Data::Type is planned to get big as more datatypes are added to collections. Therefore introspection and surfing through the collections will be essential. Especially when alternativ collections arent always installed and available. This module adds introspection/reflection of Data::Type datatypes, filters and documentation via DBI (via *ingenous* DBD::AnyData).
my $dtq = Data::Type::Query->new;
The constructor does not require arguments.
Returns the DBI $dbh handle ready for querying.
$dbh
my $href = $dtq->catalog();
Returns a hashref which hold prerendered tabular listings (as scalars).
print $href->{types}; print $href->{regexps}; print $href->{facets}; print $href->{filters};
Valid keys of that hash are retrievable with $dtq->tables.
[NOTE] Be carefull since the catalog is generated only one time (for the life time of your program) and latter calls return the cached version.
my $scalar = $dtq->toc;
Returns a static string containing a grouped listing of all know types.
my $href = $dtq->depends;
Generates a dependency tree. Which type depends on which module. Returns an hash reference with this something similar to this structure:
{ 'Locale::Language' => { 'types' => [ { 'name' => 'LANGCODE' }, { 'name' => 'LANGNAME' } ], 'version' => '2.02' }, 'Business::CreditCard' => { 'types' => [ { 'name' => 'CREDITCARD' } ], 'version' => '0.27' }, 'Email::Valid' => { 'types' => [ { 'name' => 'EMAIL' } ], 'version' => '0.14' }, }
[NOTE] In future helps implementing clever runtime module loading for only types really used.
Sourceforge http://sf.net/projects/datatype is hosting a project dedicated to this module. And I enjoy receiving your comments/suggestion/reports also via http://rt.cpan.org or http://testers.cpan.org.
Murat Uenalan, <muenalan@cpan.org>
To install Data::Type, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Type
CPAN shell
perl -MCPAN -e shell install Data::Type
For more information on module installation, please visit the detailed CPAN module installation guide.