3 Git::Object - Object-oriented interface to Git objects (base class).
7 Git::Object is a base class that provides access to commit, tag and
8 (unimplemented) tree objects. See L<Git::Commit> and L<Git::Tag>.
10 Objects are loaded lazily, and hence instantiation is free.
11 Git::Object instances stringify to their SHA1s.
22 use Encode
qw(decode);
24 use base
qw(Exporter);
27 our @EXPORT_OK = qw();
36 =item Git::Object->new($repo, $sha1)
38 Return a new Git::Object instance for the object with $sha1 in the
39 repository $repo (a Git::Repo instance).
41 Note that this method does not check whether the object exists in the
42 repository. Trying to accessing its properties through a subclass
43 will fail if the object doesn't exist, however.
48 my ($class, $repo, $sha1) = @_;
49 die "$repo is not a Git::Repo instance" unless $repo->isa('Git::Repo');
50 my $self = {repo
=> $repo, sha1
=> $sha1};
51 return bless $self, $class;
56 Return the Git::Repo instance this object was instantiated with.
66 Return the SHA1 of this object.
74 # Helper method: Decode the given octets into a Unicode string, trying
75 # the $self->{encoding} encoding first, if defined, then trying UTF-8,
76 # then falling back to Latin 1.
79 my ($self, $octets) = @_;
81 # Try $self->{encoding}:
82 eval { $string = decode
($self->{encoding
}, $octets, Encode
::FB_CROAK
) }
85 eval { $string = decode
('utf-8', $octets, Encode
::FB_CROAK
) }
86 unless defined $string;
87 # ... else fall back to Latin 1 (the first 256 Unicode code
88 # points coincide with Latin 1):
89 $string = $octets unless defined $string;