Elive

 view release on metacpan or  search on metacpan

lib/Elive/Entity/Report.pm  view on Meta::CPAN

    my $spec = shift;
    my %opt = @_;

    die "usage: $class->new(\$hashref)"
	unless Elive::Util::_reftype($spec) eq 'HASH';

    my %args = %$spec;

    $args{ownerId} ||= do {

	my $connection = $opt{connection} || $class->connection
	    or die "not connected";

	$connection->login->userId;
    };

    return \%args;
}

=head2 list

    my $all_reports = Elive::Entity::Report->list();

List reports.

Note: This command does not return the body of the report (C<xml> property).

=cut

=head2 retrieve

    my $report = Elive::Entity::Report->retrieve( $report_id );
    my $report_xml = $report->xml;

Retrieves a report, including the body of the report (C<xml> property).

=cut

=head2 insert

The C<insert> method is not available for reports.

=cut

sub insert {
    my ($class, $_spec, %opt) = @_;

    my $insert_data = $class->BUILDARGS($_spec, %opt);

    $opt{command} ||= 'addReport';

    return $class->SUPER::insert( $class->_freeze($insert_data), %opt);
}

=head2 update

The C<update> method is not available for reports.

=cut

sub update {
    my ($self, $_spec, %opt) = @_;

    my $update_data;
    $update_data = $self->BUILDARGS($_spec, %opt)
	if $_spec;
    #
    # always need to supply these fields to the update command,
    # whether or not they've actually changed.
    #
    my %changed;
    @changed{$self->is_changed, 'name','description','xml', 'ownerId'} = undef;

    return $self->SUPER::update($update_data, %opt, changed => [keys %changed]);
}

=head2 delete

    my $report = Elive::Entity::Report->retrieve( $report_id );
    $report->delete if $report;

Deletes a report.

=cut

sub delete {
    #
    # response seems to be returned as true/false rather than a record.
    # hence the need to roll our own
    #
    my ($self, %opt) = @_;

    my $som = $self->connection->call('deleteReport' 
				      => %{$self->_freeze({reportId => $self->reportId})
				      });

    my $results = $self->_get_results($som, $self->connection);
    #
    # this command responds with true/false, rather than a report record.
    #
    my $deleted = $results && $results->[0];

    return $self->_deleted($deleted);
}

1;



( run in 1.076 second using v1.01-cache-2.11-cpan-d8267643d1d )