Fedora-Bugzilla

 view release on metacpan or  search on metacpan

lib/Fedora/Bugzilla/Bug.pm  view on Meta::CPAN


use Path::Class;
use URI::Fetch;
use URI::Find;
use XML::Twig;

use Fedora::Bugzilla::Types ':all'; 
use Fedora::Bugzilla::Bug::Flag;
use Fedora::Bugzilla::Bug::Comment;
use Fedora::Bugzilla::Bug::Attachment;
use Fedora::Bugzilla::Bug::NewAttachment;

# debugging
#use Smart::Comments '###', '####';

use namespace::clean -except => 'meta';

use overload '""' => sub { shift->id }, fallback => 1;

our $VERSION = '0.13';

########################################################################
# parent Fedora::Bugzilla 

has bz => (is => 'ro', isa => 'Fedora::Bugzilla', required => 1);

########################################################################
# Handle the alias on construction correctly 

around BUILDARGS => sub {
    my $orig  = shift @_;
    my $class = shift @_; 
    
    ### in BUILDARGS...
    ##### @_

    if (@_ > 1 || ref $_[0] eq 'HASH') {

        my $args = @_ > 1 ? { @_ } : $_[0];

        if (exists $args->{alias}) {
            
            $args->{_aliases} = { $args->{alias} => 1 };
            delete $args->{alias};
            ##### $args
            return $class->$orig($args);
        }
    } 

    return $class->$orig(@_); 
}; 

########################################################################
# data: the meat of it 

# The data attibute contains the raw hashref returned by Bugs.get_bugs. Note
# that if any updates are made, this is NOT the place to do it; update() pulls
# the new values from the attributes themselves, NOT this hash.

has data =>
    (is => 'ro', isa => 'HashRef', lazy_build => 1, is_clear_master => 1);

sub _build_data {
    my $self = shift @_;

    # prefer id over alias
    my $emsg = 'Neither bug id nor alias has been provided';
    my $bug_id = $self->has_id       ? $self->id 
               : $self->_has_aliases ? $self->alias
               :                       confess $emsg
               ;

    my $ret_hash = $self->bz->rpc->simple_request(
        'Bug.get_bugs',
        { ids => [ $bug_id ] }
    );

    return $ret_hash->{bugs}->[0];
}
    
# force a reload from bugzilla by clearing data
sub refresh { shift->clear_data }

# set true when we need to do an update
has dirty => (
    clear_master => 'data',
    clearer  => 'clear_dirty',
    is       => 'rw', 
    isa      => 'Bool', 
    default  => 0,
);

# tag an attribute to update; mark the object as changed but not updated.
# this sub is the trigger used by all rw attributes
sub _dirty_trigger  {
    my ($self, $new_value, $meta) = @_;

    ### $new_value
    ### $meta

    # FIXME not exactly sure...
    return unless $meta;

    $self->dirty(1);
    $self->_to_update($meta->name);
}

# update the dirty values in bugzilla; mark clean and purge old data
sub update {
    my $self = shift @_;

    # only if we have something to update...
    return if not $self->dirty;

    # force stringification
    my %updates = 
        #map { my $x = $self->$_ || q{}; $_ => "$x" } $self->_update_these;
        map { my $x = $self->$_ || q{}; $_ => blessed $x ? "$x" : $x } $self->_update_these;
    
    ### %updates



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