Cal-DAV

 view release on metacpan or  search on metacpan

lib/Cal/DAV.pm  view on Meta::CPAN


    my $cal = Cal::DAV->new( user => $user, pass => $pass, url => $url);
    # the ics data will be fetched automatically if it's there

    # ... or you can parse some ics 
    $cal->parse(filename => $data);

    # cal now has all the methods of Data::ICal
    # you can now monkey around with the object

    # saves the updated calendar
    $cal->save;

    # deletes the calendar
    $cal->delete;

    # lock the file on the server
    $cal->lock;

    # unlock the file on the server
    $cal->unlock

    # steal the lock
    $cal->steal_lock;

lib/Cal/DAV.pm  view on Meta::CPAN

        die "You must pass in a $_ param\n" unless defined $args{$_};
        $opts{"-${_}"} = $args{$_};
    }
    my $dav  = HTTP::DAV->new;
    $dav->credentials(%opts);
    return bless { _dav => $dav, url => $args{url}, _auto_commit => $args{auto_commit} }, $class;
}

=head2 parse <arg[s]>

Make a new calendar object using same arguments as C<Data::ICal>'s C<new()> or C<parse()> methods.

Does not auto save for you.

Returns 1 on success and 0 on failure.

=cut

sub parse {
    my $self = shift;
    my %args = @_;
    $self->{_cal} = Data::ICal->new(%args);
    return (defined $self->{_cal}) ?
        $self->dav->ok("Loaded data successfully") :
        $self->dav->err('ERR_GENERIC', "Failed to load calendar: parse error $@");        
}

=head2 save [url]

Save the calendar back to the server (or optionally to another path).

Returns 1 on success and 0 on failure.

=cut

sub save {
    my $self = shift;
    my $url  = shift || $self->{url};
    my $cal  = $self->{_cal}; # TODO should this be cal()
    return 1 unless defined $cal;

lib/Cal/DAV.pm  view on Meta::CPAN


=head2 cal 

Get the underlying cal object

=cut

sub cal {
    my $self = shift;
    if (!defined $self->{_cal}) {
        my $ret = $self->get || die "Couldn't autofetch calendar: ".$self->dav->message;
    }
    return $self->{_cal};
}

=head2 auto_commit [boolean]

Whether to auto save on desctruction or not.

Defaults to 0.

t/01basics.t  view on Meta::CPAN


# Check
my $entries;
ok($entries = $cal->entries, "Got entries");
is(scalar(@$entries), 1, "Got 1 entry");

# Modify
ok($cal->add_entry(make_entry()), "Added an entry");

# Save
ok($cal->save, "Save modified calendar");

# Get
ok($entries = $cal->entries, "Got entries after modification");
is(scalar(@$entries), 2, "Got 2 entries");

# Check
$cal = undef;
ok($cal = get_cal_dav('birthday.ics'), "Instantiated yet again");
ok($entries = $cal->entries, "Got entries after modification and destroy");
is(scalar(@$entries), 2, "Still got 2 entries");



( run in 0.311 second using v1.01-cache-2.11-cpan-c333fce770f )