The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

JIRA::REST::Class::Abstract - An abstract class for JIRA::REST::Class that most of the other objects are based on.

VERSION

version 0.11

METHODS

name_for_user

When passed a scalar that could be a JIRA::REST::Class::User object, returns the name of the user if it is a JIRA::REST::Class::User object, or the unmodified scalar if it is not.

key_for_issue

When passed a scalar that could be a JIRA::REST::Class::Issue object, returns the key of the issue if it is a JIRA::REST::Class::Issue object, or the unmodified scalar if it is not.

When passed two scalars, one that could be a JIRA::REST::Class::Issue::LinkType object and another that is a direction (inward/outward), returns the name of the link type and direction if it is a JIRA::REST::Class::Issue::LinkType object, or attempts to determine the link type and direction from the provided scalars.

dump

Returns a stringified representation of the object's data generated somewhat by Data::Dumper::Concise, but not descending into any objects that might be part of that data. If it finds objects in the data, it will attempt to represent them in some abbreviated fashion which may not display all the data in the object. For instance, if the object has a JIRA::REST::Class::Issue object in it for an issue with the key 'JRC-1', the object would be represented as the string 'JIRA::REST::Class::Issue->key(JRC-1)'. The goal is to provide a gist of what the contents of the object are without exhaustively dumping EVERYTHING. I use it a lot for figuring out what's in the results I'm getting back from the JIRA API.

INTERNAL METHODS

init

Method to perform post-instantiation initialization of the object. The first argument must be the factory object which created the object. Subclasses of JIRA::REST::Class::Abstract are expected to call $self->SUPER::init(@_); somewhere in their own init().

unload_lazy

I'm using a hash to track which lazily loaded methods have already been loaded, and this method clears that hash (and the field that got loaded) so they get loaded again.

populate_scalar_data

Code to make instantiating objects from $self->{data} easier. Accepts three unnamed parameters:

  • key in this object's hash which will hold the resulting object

  • nickname for object type being created (to be passed to make_object())

  • key under $self->{data} that should be passed as the data to make_object()

populate_date_data

Code to make instantiating DateTime objects from $self->{data} easier. Accepts two unnamed parameters:

  • key in this object's hash which will hold the resulting object

  • key under $self->{data} that should be passed as the data to make_date()

populate_list_data

Code to make instantiating lists of objects from $self->{data} easier. Like "populate_scalar_data", it accepts three unnamed parameters:

  • key in this object's hash which will hold the resulting list reference

  • nickname for object type being created (to be passed to make_object()) as each item in the list

  • key under $self->{data} that should be interpreted as a list reference, each element of which is passed as the data to make_object()

populate_scalar_field

Code to make instantiating objects from $self->{data}->{fields} easier. Accepts three unnamed parameters:

  • key in this object's hash which will hold the resulting object

  • nickname for object type being created (to be passed to make_object())

  • key under $self->{data}->{fields} that should be passed as the data to make_object()

populate_list_field

Code to make instantiating lists of objects from $self->{data}->{fields} easier. Like "populate_scalar_field", it accepts three unnamed parameters:

  • key in this object's hash which will hold the resulting list reference

  • nickname for object type being created (to be passed to make_object()) as each item in the list

  • key under $self->{data}->{fields} that should be interpreted as a list reference, each element of which is passed as the data to make_object()

mk_contextual_ro_accessors

Because I didn't want to give up Class::Accessor::Fast, but wanted to be able to make contextual accessors when it was useful. Accepts a list of accessors to make.

mk_deep_ro_accessor

Why do accessors have to be only for the top level of the hash? Why can't they be several layers deep? This method takes a list of keys for the hash this object is based on and creates a contextual accessor that goes down deeper than just the first level.

  # create accessor for $self->{foo}->{bar}->{baz}
  __PACKAGE__->mk_deep_ro_accessor(qw/ foo bar baz /);

mk_lazy_ro_accessor

Takes two parameters: field to make a lazy accessor for, and a subroutine reference to construct the value of the accessor when it IS loaded.

This method makes an accessor with the given name that checks to see if the value for the accessor has been loaded, and, if it hasn't, runs the provided subroutine to construct the value and stores that value for later use. Especially good for loading values that are objects populated by REST calls.

  # code to construct a lazy accessor named 'foo'
  __PACKAGE__->mk_lazy_ro_accessor('foo', sub {
      my $self = shift;
      # make the value for foo, in say, $foo
      return $foo;
  });

mk_data_ro_accessors

Makes accessors for keys under $self->{data}

mk_field_ro_accessors

Makes accessors for keys under $self->{data}->{fields}

make_subroutine

Takes a subroutine name and a subroutine reference, and blesses the subroutine into the class used to call this method. Can be called with either a class name or a blessed object reference.

jira

Returns a JIRA::REST::Class object with credentials for the last JIRA user.

factory

An accessor for the JIRA::REST::Class::Factory.

JIRA_REST

An accessor that returns the JIRA::REST object being used.

REST_CLIENT

An accessor that returns the REST::Client object inside the JIRA::REST object being used.

JSON

An accessor that returns the JSON object inside the JIRA::REST object being used.

make_object

A pass-through method that calls JIRA::REST::Class::Factory::make_object().

make_date

A pass-through method that calls JIRA::REST::Class::Factory::make_date().

class_for

A pass-through method that calls JIRA::REST::Class::Factory::get_factory_class().

obj_isa

When passed a scalar that could be an object and a class string, returns whether the scalar is, in fact, an object of that class. Looks up the actual class using class_for(), which calls JIRA::REST::Class::Factory::get_factory_class().

cosmetic_copy THING

A utility function to produce a "cosmetic" copy of a thing: it clones the data structure, but if anything in the structure (other than the structure itself) is a blessed object, it replaces it with a stringification of that object that probably doesn't contain all the data in the object. For instance, if the object has a JIRA::REST::Class::Issue object in it for an issue with the key 'JRC-1', the object would be represented as the string 'JIRA::REST::Class::Issue->key(JRC-1)'. The goal is to provide a gist of what the contents of the object are without exhaustively dumping EVERYTHING.

RELATED CLASSES

AUTHOR

Packy Anderson <packy@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Packy Anderson.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)