Fedora-Bugzilla

 view release on metacpan or  search on metacpan

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


    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

    my $ret = $self->bz->rpc->simple_request(
        'Bug.update',
        {
            ids     => [ $self->id ],
            updates => \%updates,
        }
    );

    # clear our old data (force a reload), etc.
    $self->clear_data;
    $self->clear_dirty;

    # FIXME should probably figure out something better to return
    return $ret;
}

########################################################################
# some defaults to help make things a little easier :) 

# default attribute attributes :-)
my @defaults = (
    clear_master   => 'data',
    is         => 'ro', 
    isa        => 'Str', 
    lazy_build => 1,
);

my @rw_defaults = ( 
    clear_master   => 'data',

    is         => 'rw', 
    isa        => 'Str', 
    lazy_build => 1, 
    trigger    => \&_dirty_trigger,
);

my @dt_defaults = (
    clear_master   => 'data',

    is         => 'ro', 
    # FIXME hm.
    #isa        => BugzillaDateTime, 
    isa        => DateTime, 
    lazy_build => 1,
    coerce     => 1,
);

########################################################################



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