App-Office-Contacts

 view release on metacpan or  search on metacpan

lib/App/Office/Contacts/Controller/Exporter/Report.pm  view on Meta::CPAN

package App::Office::Contacts::Controller::Exporter::Report;

use strict;
use utf8;
use warnings;
use warnings  qw(FATAL utf8); # Fatalize encoding glitches.

use App::Office::Contacts::Util::Validator;

use Encode; # For encode().

use Sub::Exporter -setup =>
{
	exports =>
	[qw/
		display
	/],
};

use Try::Tiny;

our $VERSION = '2.04';

# -----------------------------------------------

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

	$self -> log(debug => "Controller::Exporter::Report.display()");

	$self -> param('db') -> simple -> begin_work;
	$self -> add_header('-Status' => 200, '-Content-Type' => 'text/xml; charset=utf-8');

	my($response, $result);

	try
	{
		$result = App::Office::Contacts::Util::Validator -> new
		(
			app    => $self,
			config => $self -> param('config'),
			db     => $self -> param('db'),
			query  => $self -> query,
		) -> report;

		if ($result -> success)
		{
			$response = $self -> param('db') -> library -> build_ok_xml
				(
					$self -> param('view') -> report -> generate_report($result)
				);
		}
		else
		{
			$response = $self -> param('db') -> library -> build_error_xml
			(
				'Cannot generate report',
				$result,
			);
		}

		$self -> param('db') -> simple -> commit;
	}
	catch
	{
		my($error) = $_;

		$self -> param('db') -> simple -> rollback;

		# Try to log the error despite the error.

		$self -> log(error => "System error: $error");

		$response = $self -> param('system_error');
	};

	return encode('utf-8', $response);

} # End of display.

# -----------------------------------------------

1;

=head1 NAME

App::Office::Contacts::Controller::Exporter::Report - A web-based contacts manager

=head1 Synopsis

See L<App::Office::Contacts/Synopsis>.



( run in 1.200 second using v1.01-cache-2.11-cpan-39bf76dae61 )