GD-Dashboard

 view release on metacpan or  search on metacpan

Dashboard.pm  view on Meta::CPAN

      FNAME => '',
      QUALITY => 100
   };


   # load in options supplied to new()
   for (my $x = 0; $x <= $#_; $x += 2) 
   {
      my $opt = uc($_[$x]);
      
      defined($_[($x + 1)]) or die "Dashboard->new() called with odd number of option parameters - should be of the form option => value";
      $self->{$opt} = $_[($x + 1)]; 
   }

   bless($self);
   return $self;
}

#
# There can be many meters on a graphic.  To specify them, 
# you create a new meter, then pass it to this function, 
# along with its name.  All meters will be referred to by
# name.
#
sub add_meter
{
   my ($self,$name,$meter) = @_;
   $self->{METERS}->{$name} = $meter;
}

#
# Why would you want to use get_meter?  A couple of reasons.
# First, you might have called add_meter(new Dashboard::Gauge()).
# Second, if you have multiple dash layouts, you have probably
# written the code so that you don't have access to the original
# meter variables at the point where you need to set them.
# 
sub get_meter
{
   my ($self,$name) = @_;   
   $self->{METERS}->{$name};
}

sub gdimage
{
   my ($self) = @_;
   my ($aref) = $self->{METERS};
   my $fname = $self->{FNAME};
   
   if (!defined($fname) || $fname eq '')
   {
      warn("GD::Dashboard::gdimage(): You must set FNAME in constructor first!") ;
      return undef;
   }
   
   # Get canvas from specified background graphics   
   my $im;
   
   if ($self->{FNAME} =~ /png$/ )
   {
      $im = GD::Image->newFromPng($self->{FNAME});
   }
   else
   {
      $im = GD::Image->newFromJpeg($self->{FNAME});
   }
   
   # Draw all my meters
   for my $m (keys(%{$aref}))
   {
      my $m2 = $aref->{$m};
      $m2->write_gdimagehandle($im);
   }

   $im;
}

sub png
{
   my ($self) = @_;

   my $im = $self->gdimage;

   return $im->png();
}

sub jpeg
{
   my ($self) = @_;

   my $im = $self->gdimage;

   return $im->jpeg($self->{QUALITY});
}

#
# Is anything wrong with me using this filehandle (HG1) ?
#
sub write_jpeg
{
   my ($self,$fname) = @_;
   
   open (HG1,'>'.$fname);
   binmode HG1;
   print HG1 $self->jpeg();
   close HG1;
}

sub write_png
{
   my ($self,$fname) = @_;
   
   open (HG1,'>'.$fname);
   binmode HG1;
   print HG1 $self->png();
   close HG1;
}

package GD::Dashboard::Base;

# insert base class for meters here.....



( run in 1.186 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )