Daniel Muey > Mac-SysProfile-0.05 > Mac::SysProfile

Download:
Mac-SysProfile-0.05.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.05   Source  

NAME ^

Mac::SysProfile - Perl extension for OS X system_profiler

SYNOPSIS ^

  use Mac::SysProfile;
  my $pro = Mac::SysProfile->new(); 
  print 'OS X Version ' . $pro->osx() . "\n";
  print 'Darwin Version ' . $pro->darwin() . "\n";

DESCRIPTION ^

OO interface to your Mac's system_profiler

METHODS ^

$pro->types()

Returns an array ref of the datatypes available use for $pro->gettype()

$pro->gettype()

Returns a data structure of the given type's data.

  my $soft = $pro->gettype('SPSoftwareDataType');

Once you call it for a type it returns the cached data on the next call unless the second argument is true.

  my $soft = $pro->gettype('SPSoftwareDataType',1);

The data structure is an array ref of hashes. These hashes can be arbitrarily complex.

A hash at any point in that structure may or may not have a '_name' key. It is left in place to keep from making the already complex structure arbitrarily more complex.

Use it or ignore it as appropriate to your needs.

$pro->osx()

Returns the system's OSX version. The first time it is called it finds it and stores it in the object for less overhead:

  if($pro->osx() eq '10.3.9') { # initially finds it
     print 'Do you want to upgrade from ' . $pro->osx() . "\n"; # already processed so it returns the cached value (IE Fast)
  } 
  print 'Your current version is: ' . $por->osx() . "\n";  # already processed so it returns the cached value (IE Fast)

You can make it reprocess and find it again fresh by giving it a true value:

  if($pro->osx() eq '10.3.9') { # initially finds it
     print 'Do you want to upgrade from ' . $pro->osx(1) . "\n"; # finds it again from scratch instead of the cached value (IE slower)
  } 
  print 'Your current version is: ' . $por->osx(1) . "\n";  # finds it again from scratch instead of the cached value (IE slower)

$pro->darwin()

Same useage as $pro->osx() but returns the version of the system's Darwin.

$pro->state_hashref()

Returns a hashref of the entire object so far. Anything that has not been called it undef.

$pro->xml()

Returns an xml document of the type specified. An optional file handle or file to write the output to can be specified as the second argument. If you put it in a file that has a .spx extension then it will be an XML file which can be opened by System Profiler.app

  my $raw = $pro->xml('SPSoftwareDataType');
  $pro->xml('SPSoftwareDataType','./software.spx') or die "Could not create xml file: $!";
  $pro->xml('SPSoftwareDataType',\*FH);

SAMPLE ^

  # create xml files for each type in ./10.3.9/
  use Mac::SysProfile;
  my $pro = Mac::SysProfile->new();
  mkdir $pro->osx() or die "Could not mkdir: $!" if !-d $pro->osx();
  for(@{ $pro->types() }) {
     $pro->xml($_, $pro->osx() . "/$_.spx") or warn "$_.spx failed: $!";
  }

Pre v0.04 caveat ^

The data structure format is changed in 0.04 since parsing the non-XML output reliably is impossible (but seems to work fine at first glance).

MISC ^

It doesn't currently use the "detailLevel" option.

AUTHOR ^

Daniel Muey, http://drmuey.com/cpan_contact.pl

COPYRIGHT AND LICENSE ^

Copyright 2005 by Daniel Muey

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

syntax highlighting: