Net::Duo::Object(3pm)
π Net::Duo::Object β the helper base class bestie β¨
okay so this is Net::Duo::Object(3pm), straight out of the User Contributed Perl Documentation, and it's giving "internal plumbing that makes the whole Net::Duo thing work" π
πΈ NAME
Net::Duo::Object β the helper base class for Duo objects. it's the parent class, the blueprint, the main character that all the other Duo object classes inherit from π«Ά
β¨ SYNOPSIS
okay so here's how you actually use this thing. you make a package, you use parent, you write a fields method, and then you call install_accessors:
package Net::Duo::Admin::Token 1.00;
use parent qw(Net::Duo::Object);
sub fields {
return {
token_id => 'simple',
type => 'simple',
serial => 'simple',
users => 'Net::Duo::Admin::User',
};
}
Net::Duo::Admin::Token->install_accessors;
see? slay. that's the whole vibe π
π REQUIREMENTS
you're gonna need Perl 5.14 or later, plus these modules: HTTP::Request and HTTP::Response (which are part of HTTP::Message), JSON, LWP (also known as libwww-perl), Perl6::Slurp, Sub::Install, and URI::Escape (part of URI). good news bestie: all of them are available from CPAN π
π¦ DESCRIPTION
so the Duo API is full of objects β like, a whole variety of them β and they're represented as JSON objects with multiple fields. and plot twist: these objects often embed other objects inside them. nesting. we love to see it π
to give you a nice Perl API β with getters, setters, and commit and delete methods on individual objects β the move is to wrap these Duo REST API objects in Perl classes. cute, right?
this module is the base class for all of those. it does the dirty work of constructing an object from decoded JSON data and building the accessors automatically from a field specification β¨
lowkey important: this class should normally be considered an internal implementation detail of the Net::Duo API. only developers of the Net::Duo modules should need to worry about it. regular callers can use the other Net::Duo API objects without knowing anything about how this class works. no cap π
π FIELD SPECIFICATION
any class that wants to use Net::Duo::Object to construct itself has to provide a field specification. it's a data structure that describes all the data fields in that object. it gets used by two things:
- the generic
Net::Duo::Objectconstructor, to build the Perl data structure for an object - the
install_accessors()class method, to create the accessors for the class
the client class must provide a class method named _fields() that returns a reference to a hash π₯
- the keys of the hash are the field names of the data stored in an object of that class.
- the values specify the type of data stored in that field.
each value may be either a simple string or a reference to an array β in which case the first value is the type and the remaining values are flags.
π the types (must be chosen from these)
"array"β an array of simple text, number, or boolean values."simple"β a simple text, number, or boolean field,- class β the name of a class. this field should then contain an array of zero or more instances of that class, and the constructor for that class will be called with the resulting structures.
π the flags (must be chosen from these)
"boolean"β this is a boolean field. convert all values to"true"or"false"before sending the data to Duo. only makes sense with a field of type"simple"."set"β generate a setter for this field.install_accessors()will, in addition to adding a method to retrieve the value, add a method named after the field but prefixed withset_that will set the value of that field and remember that it's been changed locally. changed fields will then be pushed back to Duo via thecommit()method. π"zero_or_one"β this is a boolean field that wants values of0or1. convert all values to1or0before sending the data to Duo. only makes sense with a field of type"simple".
π CLASS METHODS
create(DUO, URI, DATA)β a general constructor for creating a new object in Duo. takes a Net::Duo object, the URI of the REST endpoint for object creation, and a reference to a hash of object data. this method should be overridden by subclasses to provide the URI and only expose theDUOandDATAarguments to the caller. returns the newly-blessed object containing the data returned by Duo β¨install_accessors()β using the field specification, creates accessor functions for each data field that return copies of the data stored in that field, orundefif there is no data.new(DUO, DATA)β a general constructor for Net::Duo objects. takes a Net::Duo object and a reference to a hash, which contains the data for an object of the class being constructed. using the field specification for that class, the data will be copied out of the object into a Perl data structure, converting nested objects to other Net::Duo objects as required.
π INSTANCE METHODS
commit(URI)β a general method for committing changes to an object to Duo. takes the URI of the REST endpoint for object modification. this method should be overridden by subclasses to provide the URI and only expose an argument-less method.
after commit(), the internal representation of the object will be refreshed to match the new data returned by the Duo API for that object. therefore, other fields of the object may change after commit() if some other user has changed other, unrelated fields in the object. π
it's best to think of this method as a synchronize operation: changed data is written back, overwriting what's in Duo, and unchanged data may be overwritten by whatever is currently in Duo, if it is different.
json()β convert the data stored in the object to JSON and return the results. the resulting JSON should match the JSON that one would get back from the Duo web service when retrieving the same object (plus any changes made locally to the object viaset_*()methods). this is primarily intended for debugging dumps or for passing Duo objects to other systems via further JSON APIs. π§
π AUTHOR
Russ Allbery <rra@cpan.org>
π COPYRIGHT AND LICENSE
Copyright 2015 Russ Allbery <rra@cpan.org>
Copyright 2014 The Board of Trustees of the Leland Stanford Junior University
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
π SEE ALSO
Net::Duo
this module is part of the Net::Duo distribution. the current version of Net::Duo is available from CPAN, or directly from its web site at <https://www.eyrie.org/~eagle/software/net-duo/> π¦
okay bestie that's the whole page π
this one was rendered by perl v5.36.0 on 2022-12-18, and it's Net::Duo::Object(3pm) β go forth and build ur accessors, ily π«Άβ¨
π¦ where this page comes from
- debian bookworm: libnet-duo-perl 1.02-3 Β· MIT
- debian trixie: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu noble: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu resolute: libnet-duo-perl 1.02-3 Β· MIT
- ubuntu stonking: libnet-duo-perl 1.02-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms