CPANDB::Ticket(3pm)
π CPANDB::Ticket π
okay bestie, welcome to CPANDB::Ticket, a whole entire Perl module β it's the CPANDB class for the ticket table π and yes it ships as part of the User Contributed Perl Documentation collection, so you know it's the real deal. pull up a chair, grab a strawberry π, let's get into it.
β¨ NAME β¨
CPANDB::Ticket β CPANDB class for the ticket table π
π¦ DESCRIPTION π¦
TO BE COMPLETED
(not me reading that and going π β that's literally what it says, so that's what you get. the docs said it, not me.)
π METHODS π
πΈ base
# Returns 'CPANDB'
my $namespace = CPANDB::Ticket->base;
so like, normally you're only ever working with one table class, and only with one ORLite package. that's the vibe. that's the whole situation.
BUT. if for some reason you need to juggle multiple ORLite packages at the same time and you don't wanna hardcode the root namespace over and over like a menace, you can just ask an object or a table class what its root namespace is using the base method. lowkey genius, honestly.
π table
# Returns 'ticket'
print CPANDB::Ticket->table;
for simple operations you should not need the name of the table, fr fr. but every now and then you might need it programatically, and if that day comes, table has your back β it hands you the table name. no cap. π«Ά
π§ load
my $object = CPANDB::Ticket->load( $id );
if your table has a single column primary key, a load method gets generated in the class. if there's no primary key, the method is simply not created. it's giving "if you know you know" β iykyk.
load is the shortcut for fetching a single object based on the value of the primary key. but listen β it should only be used for cases where your code trusts the record to already exist. it's a shortcut, not a safety net, bestie.
it returns a CPANDB::Ticket object, or throws an exception if the object does not exist. π
π select
# Get all objects in list context
my @list = CPANDB::Ticket->select;
# Get a subset of objects in scalar context
my $array_ref = CPANDB::Ticket->select(
'where id > ? order by id',
1000,
);
select runs a typical SQL SELECT query on the ticket table. classic.
it takes an optional argument of a SQL phrase to be added after the FROM ticket section of the query, followed by variables to be bound to the placeholders in the SQL phrase. any SQL that is compatible with SQLite can be used in the parameter. anything. go off.
returns a list of CPANDB::Ticket objects when called in list context, or a reference to an ARRAY of CPANDB::Ticket objects when called in scalar context. context really said "choose your own adventure" β¨
throws an exception on error, typically directly from the DBI layer. π
β iterate
CPANDB::Ticket->iterate( sub {
print $_->id . "\n";
} );
iterate lets you process large tables one record at a time without having to load them all into memory in advance. this is the whole point. this is the moment. π
it plays so well to the strength of SQLite, letting it do the work of loading an arbitrarily large stream of records from disk while retaining the full power of Perl when processing the records. it's giving collaboration. it's giving teamwork. π
the last argument to iterate must be a subroutine reference that will be called for each element in the list, with the object provided in the topic variable $_.
this makes the iterate code fragment above functionally equivalent to the following β except with an O(1) memory cost instead of O(n). obsessed.
foreach ( CPANDB::Ticket->select ) {
print $_->id . "\n";
}
you can filter the list via SQL in the same way you can with select.
CPANDB::Ticket->iterate(
'order by ?', 'id',
sub {
print $_->id . "\n";
}
);
you can also use it in raw form from the root namespace for better control. using this form also allows for the use of arbitrarily complex queries, including joins. instead of being objects, rows are provided as ARRAY references when used in this form.
CPANDB->iterate(
'select name from ticket order by id',
sub {
print $_->[0] . "\n";
}
);
π count
# How many objects are in the table
my $rows = CPANDB::Ticket->count;
# How many objects
my $small = CPANDB::Ticket->count(
'where id > ?',
1000,
);
count runs a SELECT COUNT(*) query on the ticket table. it's the "how many bestie" method. π₯
it takes an optional argument of a SQL phrase to be added after the FROM ticket section of the query, followed by variables to be bound to the placeholders in the SQL phrase. any SQL that is compatible with SQLite can be used in the parameter.
returns the number of objects that match the condition. a number. a vibe check in integer form. β¨
throws an exception on error, typically directly from the DBI layer. π
π ACCESSORS π
π id
if ( $object->id ) {
print "Object has been inserted\n";
} else {
print "Object has not been inserted\n";
}
returns true, or throws an exception on error.
REMAINING ACCESSORS TO BE COMPLETED
(she's a work in progress, your honor π)
πΈ SQL πΈ
the ticket table was originally created with the following SQL command. verbatim, character for character, because we do not mess with the source of truth:
CREATE TABLE ticket (
id REAL NOT NULL,
distribution TEXT NOT NULL,
subject TEXT NOT NULL,
status TEXT NOT NULL,
severity TEXT NOT NULL,
created TEXT NOT NULL,
updated TEXT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (distribution) REFERENCES distribution (distribution)
)
look at those NOT NULLs. every single one of them. no column left behind. π
π«Ά SUPPORT π«Ά
CPANDB::Ticket is part of the CPANDB API.
see the documentation for CPANDB for more information. that's the main character, this is the supporting cast. π
β¨ AUTHOR β¨
Adam Kennedy <adamk@cpan.org>
π COPYRIGHT π
Copyright 2009 - 2012 Adam Kennedy.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
the full text of the license can be found in the LICENSE file included with this module.
and that's the whole page, bestie!! π¦π this was perl v5.36.0, dated 2023-10-01, and honestly? iconic. go write something slay. periodt. π β¨
π¦ where this page comes from
- debian trixie: libcpandb-perl 0.19-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcpandb-perl 0.19-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcpandb-perl 0.19-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcpandb-perl 0.19-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms