| 1 | package Giddy; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Schema-less, versioned media/document database based on Git. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Git::Repository 1.18; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Giddy::Database; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = "0.013_001"; | |||||||||||||||||||||||||||
| 13 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Giddy - Schema-less, versioned media/document database based on Git. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 VERSION | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | version 0.013_001 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Giddy; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | my $giddy = Giddy->new; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | my $db = $giddy->get_database('/path/to/database'); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | WARNING: THIS IS ALPHA SOFTWARE, RELEASED FOR TESTING PURPOSES ONLY. DO | ||||||||||||||||||||||||||||
| 34 | NOT USE IT ON A PRODUCTION ENVIRONMENT YET. IT'S INCOMPLETE, BUG-RIDDEN, LIKELY | ||||||||||||||||||||||||||||
| 35 | TO CHANGE, AND WILL RUN OVER YOUR CAT. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Giddy is a schema-less (as in NoSQL), versioned database system for Unix-like | ||||||||||||||||||||||||||||
| 38 | operating systems, built on top of Git. A database in Giddy is simply a Git | ||||||||||||||||||||||||||||
| 39 | repository, providing the database with automatic, comprehensive versioning and | ||||||||||||||||||||||||||||
| 40 | distributive capabilities. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | As opposed to most modern database systems, Giddy aims to be human editable. | ||||||||||||||||||||||||||||
| 43 | One can create/edit/delete database entries with nothing but a text editor | ||||||||||||||||||||||||||||
| 44 | and some simple git commands (YAML has been chosen as the serialization | ||||||||||||||||||||||||||||
| 45 | format since YAML is well suited as a human editable format; however, JSON | ||||||||||||||||||||||||||||
| 46 | support is planned). This module provides an API for usage by Perl applications. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Main database features (not all features implemented yet): | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =over | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item * Human editable | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =item * Multiple version concurrency | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item * Concurrent transactions | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item * Distributed peers | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item * Disconnected operation | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =item * Consistent UTF-8 encoding | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item * Other fancy words | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =back | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | STOP: This document (and all other module documentation provided with the | ||||||||||||||||||||||||||||
| 69 | distribution) are for reference purposes only. Please read L<Giddy::Manual> | ||||||||||||||||||||||||||||
| 70 | before using Giddy to learn about the database system and how to use it. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head2 new() | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Creates a new instance of this module. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 OBJECT METHODS | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head2 get_database( $path ) | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Returns a L<Giddy::Database> object tied to a Git repository located on the file | ||||||||||||||||||||||||||||
| 83 | system. Please provide full path names to prevent potential problems. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | If the path doesn't exist, Giddy will attempt to create it and initialize it | ||||||||||||||||||||||||||||
| 86 | as a Git repository. It will also create an empty file called ".giddy" inside | ||||||||||||||||||||||||||||
| 87 | the database and perform an initial commit. You can safely remove that file | ||||||||||||||||||||||||||||
| 88 | after that. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub get_database { | ||||||||||||||||||||||||||
|
Subroutine
get_database: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 1 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # remove trailing slash, if exists | ||||||||||||||||||||||||||||
| 96 | 1 | ▶ | $path =~ s!/$!! if $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | croak "You must provide the path to the Giddy database." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | unless $path; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # is this an existing database or a new one? | ||||||||||||||||||||||||||||
| 102 | 1 | ▶ | if (-d $path && -d "${path}/.git") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $path and -d "$path/.git"
MC/DC0%0/2
-d $path and -d "$path/.git"
-d $path
-d "$path/.git"
Truth table33%1/3
A and B
A= -d $pathB= -d "$path/.git"
| |||||||||||||||||||||||||||||
| 103 | # existing | ||||||||||||||||||||||||||||
| 104 | 0 | return Giddy::Database->new(_repo => Git::Repository->new(work_tree => $path)); | |||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||
| 106 | # new one, let's create the repository's directory | ||||||||||||||||||||||||||||
| 107 | 1 | ▶ | Git::Repository->run('init', $path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | || croak "Failed creating new Giddy repository, please check provided path is valid and that you have appropriate permissions to create the repository."; | ||||||||||||||||||||||||||||
| 109 | 1 | my $db = Giddy::Database->new(_repo => Git::Repository->new(work_tree => $path)); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # create an empty .giddy file, stage it and commit, so our database will be "live" | ||||||||||||||||||||||||||||
| 112 | 1 | $db->_touch('.giddy'); | |||||||||||||||||||||||||||
| 113 | 1 | $db->stage('.giddy'); | |||||||||||||||||||||||||||
| 114 | 1 | $db->commit('initial commit'); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | return $db; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Ido Perlmuter, C<< <ido at ido50.net> >> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 BUGS | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | Please report any bugs or feature requests to C<bug-giddy at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 127 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Giddy>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 128 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | perldoc Giddy | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | You can also look for information at: | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =over 4 | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Giddy> | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | L<http://annocpan.org/dist/Giddy> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | L<http://cpanratings.perl.org/d/Giddy> | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | L<http://search.cpan.org/dist/Giddy/> | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =back | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | Copyright 2011 Ido Perlmuter. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 163 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 164 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||