# autolatex - Progress.pm # Copyright (C) 2013 Stephane Galland # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. =pod =head1 NAME Progress.pm - Implementation of a progress indicator =head1 DESCRIPTION Provides a tool to show the progress of the tasks. To use this library, type C. =head1 GETTING STARTED =head2 Initialization To create a progress tool, say something like this: use AutoLaTeX::Core::Progress; my $max = 100; my $progress = AutoLaTeX::Core::Progress->new($max) ; ...or something similar. =head1 METHOD DESCRIPTIONS This section contains only the methods in Progress.pm itself. =over =cut package AutoLaTeX::Core::Progress; our @ISA = qw( Exporter ); our @EXPORT = qw( ); our @EXPORT_OK = qw(); require 5.014; use strict; use utf8; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); use Exporter; use Carp; use AutoLaTeX::Core::IntUtils; use AutoLaTeX::Core::Util qw($INTERNAL_MESSAGE_PREFIX); our $VERSION = '4.0'; #------------------------------------------------------ # # Constructor # #------------------------------------------------------ sub new(;$) : method { my $proto = shift; my $class = ref($proto) || $proto; my $parent = ref($proto) && $proto ; my $max = $_[0]; if (!defined($max) || $max<0) { $max = 100; } my $self; if ( $parent ) { %{$self} = %{$parent} ; } else { $self = { 'child' => undef, 'max' => $max, 'value' => 0, 'parent' => undef, 'bar-width' => 30, 'comment' => '', 'comment-to-display' => '', 'previous-message-size' => 0, 'carriage-return' => 1, }; } bless( $self, $class ); return $self; } sub _newChild($$$) : method { my $proto = shift; my $class = ref($proto) || $proto; my $parent = shift; my $min = shift; my $max = shift; my $self = { 'child' => undef, 'value' => 0, 'parent' => $parent, 'min-in-parent' => $min, 'max-in-parent' => $max, 'max' => 0, 'comment' => '', }; bless( $self, $class ); return $self; } =pod =item * setCarriageReturn($) Enable or disable the use of the carraige-return character C<\r> at the end of the lines. If the carriage-return character is not used, the new-line character C<\n> is used. =over 4 =item B =over =cut sub setCarriageReturn($) : method { my $self = shift; $self->{'carriage-return'} = shift; } =pod =item * getCarriageReturn() Replies if the carriage-return character is used at the end of the output lines. =cut sub getCarriageReturn() : method { my $self = shift; return $self->{'carriage-return'}; } =pod =item * setBarWidth($) Set the number of characters for rendering the progress bar. =over 4 =item B is the number of characters of the bar. =over =cut sub setBarWidth($) : method { my $self = shift; my $width = shift; if ($self->{'parent'}) { $self->{'parent'}->setBarWidth($width); } else { $self->{'bar-width'} = $width; } } =pod =item * getBarWidth() Replies the number of characters for rendering the progress bar. =cut sub getBarWidth() : method { my $self = shift; if ($self->{'parent'}) { return $self->{'parent'}->getBarWidth(); } else { return $self->{'bar-width'}; } } =pod =item * setComment($) Set the comment associated to the progress process. =over 4 =item B